我目前正在使用Java webdriver 2.53.1 for firefox version 2.46.0。我在运行我的脚本很长一段时间后得到以下错误。由于我有不同的配置文件,使用相同的浏览器一次运行多个脚本。这个firefox浏览器似乎崩溃了。
请查看以下错误详情
org.openqa.selenium.UnhandledAlertException: Modal dialog present: A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue.
Script: https://website/js/jq…596b2b8fa35fe3a634ea342d7c3.js:1
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'MACHINE NAME', ip: 'Ip address', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=47.0.2, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 39cfd1aa-1d74-4b18-bdcd-5255a2b90127
at sun.reflect.GeneratedConstructorAccessor51.newInstance(Unknown Source)
我也应用了两种解决方案 说 1.
DesiredCapabilities capabilites = new DesiredCapabilities();
capabilites.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,UnexpectedAlertBehaviour.ACCEPT);
driver = new FirefoxDriver(capabilites);
答案 0 :(得分:0)
只有在您尝试进行页面导航但未处理屏幕警报时才会出现此错误。您需要使用IAlert
类来接受或取消此警报才能继续。
首先找到触发警报的命令,然后处理警报。
如果您详细说明了您的问题,我可能会提供更多帮助,如果您包含导致此异常的硒代码,将会很有帮助。
以下是我用来处理警报的一些功能。
public void AcceptAlert()
{
try
{
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.AlertIsPresent());
IAlert alert = Driver.SwitchTo().Alert();
alert.Accept();
}
catch (Exception)
{ }
}
public void DismissAlert()
{
try
{
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.AlertIsPresent());
IAlert alert = Driver.SwitchTo().Alert();
alert.Dismiss();
}
catch (Exception ex)
{
log.Debug(ex.Message);
}
}