在Selenium WebDriver中打开新选项卡后,如何在浏览器中将其设置为可见/活动选项卡? [英] After opening a new tab in Selenium WebDriver, how to make it the visible/active tab in my browser?

查看:701
本文介绍了在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中打开新选项卡后,如何在浏览器中将其设置为可见/活动选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆