3 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊
您可以在窗口之間切換,如下所示:
// 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)

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超10個(gè)贊
driver.switchTo().defaultContent();

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊
String parentWindow = driver.getWindowHandle();Set<String> handles = driver.getWindowHandles(); for(String windowHandle : handles) { if(!windowHandle.equals(parentWindow)) { driver.switchTo().window(windowHandle); <!--Perform your operation here for new window--> driver.close(); //closing child window driver.switchTo().window(parentWindow); //cntrl to parent window } }
添加回答
舉報(bào)