在 Selenium WebDriver 中打开一个新选项卡后,如何使其成为浏览器中的可见/活动选项卡?

After opening a new tab in Selenium WebDriver, how to make it the visible/active tab in my browser?(在 Selenium WebDriver 中打开一个新选项卡后,如何使其成为浏览器中的可见/活动选项卡?)
本文介绍了在 Selenium WebDriver 中打开一个新选项卡后,如何使其成为浏览器中的可见/活动选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用以下 WebDriver Java 代码打开一个新选项卡(当然可能有更好的方法来做到这一点):

I am using the following WebDriver Java code to open a new tab (granted there are possibly better ways to do this) :

        WebElement link = driver.findElement(By.id("home_button")); 
        Actions newTab = new Actions(driver); 
        newTab.keyDown(Keys.CONTROL).click(link).keyUp(Keys.CONTROL).build().perform();
        ArrayList<String> openTabs = new ArrayList<String> (driver.getWindowHandles());
        driver.switchTo().window(openTabs.get(1));
        driver.navigate().to("http://google.com");

而且效果很好,我所做的任何进一步操作都会应用于该新标签,但它在我的屏幕上不可见,我仍然可以看到打开的第一个标签.有什么方法可以更改在我的窗口中可见的选项卡吗?

And it works perfectly well, and any further actions I do are applied to that new tab, but it is not visible on my screen, I can still see the first tab that was opened. Is there any way to change which tab is visible in my window?

谢谢

推荐答案

切换标签,使用

newTab.sendKeys(Keys.chord(Keys.CONTROL,Keys.TAB)).perform();

这篇关于在 Selenium WebDriver 中打开一个新选项卡后,如何使其成为浏览器中的可见/活动选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)