首页 文章

使用chrome中的webdriver在标签之间切换

提问于
浏览
0

打开一个页面,对此执行一些操作,我正在使用这段代码在下一个选项卡中打开另一个链接

String url =“https://qa.logfireapps.com/lgf_700_qa_rf”;

String args1 = String.format(“window.open('%s','%s');”,url,“new”);

((JavascriptExecutor)驱动程序).executeScript(args1);

然后我需要在这两个标签之间切换 .

我用过driver.switchTo.window(parentWin);

我也用过这段代码

List windowHandles1 = new ArrayList(driver.getWindowHandles()); driver.switchTo()窗口(windowHandles1.get(1)) .

这两种情况对我来说都不起作用,但即使没有切换到第一个窗口,Web驱动程序代码仍然成功运行而没有任何错误 .

我需要切换到第一个选项卡,但所有操作都在第一个选项卡中进行,但仍然在UI中看到第二个选项卡打开,它没有切换到第一个选项卡但我的整个webdriver代码都被传递 .

据观察,切换问题只发生在这两个站点1)https://qa.logfireapps.com/lgf_700_qa/index/

2)https://qa.logfireapps.com/lgf_700_qa_rf

1 回答

  • 0

    这是我使用python的解决方案 . 抱歉没有java的例子

    def switch_to_new_window(driver, window):
        driver.switch_to_window(driver.window_handles[window])
    

相关问题