Maa*_*aal 36 selenium webdriver
我正在使用selenium webDriver为Web应用程序编写测试,并遇到了一个场景,当我尝试关闭浏览器时,我得到一个弹出窗口"你确定吗?页面要求你确认你要离开 - 输入的数据将会迷路了." 有2个按钮:保持页面和保持页面
如何点击这些按钮?
Maa*_*aal 24
( ( JavascriptExecutor ) _driver )
.executeScript( "window.onbeforeunload = function(e){};" );
Run Code Online (Sandbox Code Playgroud)
为我解决了这个问题
Bri*_*212 16
IAlert alert = driver.SwitchTo().Alert();
alert.Accept(); //for two buttons, choose the affirmative one
// or
alert.Dismiss(); //to cancel the affirmative decision, i.e., pop up will be dismissed and no action will take place
Run Code Online (Sandbox Code Playgroud)
Tim*_*the 11
您可以使用Alert API与警报等进行交互.切换到警报并确认它看起来像这样(在Java中):
Alert alert = driver.switchTo().alert();
alert.accept();
Run Code Online (Sandbox Code Playgroud)
这也在Selenium FAQ中进行了解释.
小智 6
def close_all_popups(driver):
driver.window_handles
for h in driver.window_handles[1:]:
driver.switch_to_window(h)
driver.close()
driver.switch_to_window(driver.window_handles[0])
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
73211 次 |
最近记录: |