美文网首页
Selenium打开chrome浏览器新标签页

Selenium打开chrome浏览器新标签页

作者: 夏木_ab9f | 来源:发表于2019-07-22 15:45 被阅读0次

chrome浏览器打开标签页的快捷键是ctrl+t,可以把ctrl+t的按键事件传入,以下列出两种:

1.

'''Actions actionOpenLinkInNewTab = new Actions(driver);

actionOpenLinkInNewTab.keyDown(Keys.CONTROL).sendKeys("t").keyUp(Keys.CONTROL).perform();'''

2.

'''driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");'''

经实践证明,以上两种操作对新的Chrome浏览器无效,以下是第三种,以执行js的方式实现

'''String testUrl = "https://www.jianshu.com/p/5964dc911d39";

JavascriptExecutor js = (JavascriptExecutor)driver;

js.executeScript("window.open('" +

        testUrl +

        "');");'''

相关文章

网友评论

      本文标题:Selenium打开chrome浏览器新标签页

      本文链接:https://www.haomeiwen.com/subject/wckstxtx.html