本文介绍了如何切换到新的浏览器窗口,单击按钮后打开该窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有情况,当点击按钮打开带有搜索结果的新浏览器窗口时。

I have situation, when click on button opens the new browser window with search results.

有没有办法连接并关注新打开的浏览器窗口?

然后使用它,然后返回到原始(第一个)窗口。

And work with it, then return back to original(first) window.

推荐答案

您可以在以下窗口之间切换:

You can switch between windows as below:

// Store the current window handle
String winHandleBefore = driver.getWindowHandle();

// Perform the click operation that opens new window

// Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
    driver.switchTo().window(winHandle);
}

// Perform the actions on new window

// Close the new window, if that window no more required
driver.close();

// Switch back to original browser (first window)
driver.switchTo().window(winHandleBefore);

// Continue with original browser (first window)

这篇关于如何切换到新的浏览器窗口,单击按钮后打开该窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 21:15