-1
我遇到了网页上的模式对话框。我必须在模式对话框中选择“是”,但无法选择它。我尝试过使用警报选项,但无法正常工作。我试过的代码是如何处理selenium webdriver中的模态对话框?
IAlert alert = driver.SwitchTo().Alert();
alert.Accept();
此代码不适用于模式对话框。
我遇到了网页上的模式对话框。我必须在模式对话框中选择“是”,但无法选择它。我尝试过使用警报选项,但无法正常工作。我试过的代码是如何处理selenium webdriver中的模态对话框?
IAlert alert = driver.SwitchTo().Alert();
alert.Accept();
此代码不适用于模式对话框。
你所说用来处理警报代码:
driver.SwitchTo().Alert();
它不会与模态窗口中工作。
您需要以不同的方式处理模态窗口,如普通的webElement。例如:
remove().click() //operation leading to appearance of modal window
val modalWindow = driver.findElement(By.cssSelector(".modal")) //modal window, check the DOM for it's correct selector
acceptDeletionModal.YOUR_OPERATION
我相信accept()是用于js alert类型的弹出窗口。我想你必须等待元素。或者如果您的对话框出现在Iframe中,则切换到该框架。您正在使用的实际来源将有助于查看。 – bcar 2014-10-27 00:45:47