我遇到的情况是,单击按钮打开带有搜索结果的新浏览器窗口。
有什么方法可以连接并聚焦到新打开的浏览器窗口吗?
并使用它,然后返回到原始(第一个)窗口。
你可以在以下窗口之间切换:
// 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)