Har*_*gam 13 selenium webdriver
如何使用Selenium WebDriver打开新标签?
我想在新标签中打开多个链接.这是为了尽快完成构建验证任务.因此,在每个新标签中,可以打开所有与烟雾测试相关的链接,然后在每个对应于烟雾测试要求的标签内,我们可以进行健全性测试.
码:
WebDriver wd = new FirefoxDriver();
wd.get("http://www.gmail.com");
wd.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);    
wd.manage().window().maximize();
//To open a new tab         
Robot r = new Robot();                          
r.keyPress(KeyEvent.VK_CONTROL); 
r.keyPress(KeyEvent.VK_T); 
r.keyRelease(KeyEvent.VK_CONTROL); 
r.keyRelease(KeyEvent.VK_T);    
//To switch to the new tab
ArrayList<String> tabs = new ArrayList<String>(wd.getWindowHandles());
wd.switchTo().window(tabs.get(1));
//To navigate to new link/URL in 2nd new tab
wd.get("http://facebook.com");
在新选项卡中打开链接的唯一方法是模拟键盘快捷键。以下内容适用于 FFX、Chrome 和 IE
Selenium(目前)在浏览器窗口中没有任何选项卡的概念,因此为了打开选项卡然后对其进行测试,您必须使用选项 3。
以下代码将执行选项 3. 然后立即关闭该新选项卡。(在 C# 中)
new Actions(WebDriver)
    .KeyDown(Keys.Control)
    .KeyDown(Keys.Shift)
    .Click(tab)
    .KeyUp(Keys.Shift)
    .KeyUp(Keys.Control)
    .Perform();
new Actions(WebDriver)
    .SendKeys(Keys.Control + "w")
    .Perform();
您还可以使用:
.MoveToElement(tab)
.Click()
在第一个选项的中间,以及
.KeyDown(Keys.Control)
.KeyDown("w")
.KeyUp("w")
.KeyUp(Keys.Control)
在第二个。
| 归档时间: | 
 | 
| 查看次数: | 57703 次 | 
| 最近记录: |