selenium webdrive and checking alert messages
I am parsing my page wi开发者_如何转开发th selenium and i am handling javascript alert messages with selenium to. But this is very slow to check every page if it has JS alert popup message becouse all of them doesn't. How to make this faster becouse now takes more than 1s for every cheking time.
code for checking JS alert popup with selenium webdrive
try
{
webDriver.SwitchTo().Alert().Accept(); // prepares Selenium to handle alert
}
catch (NoAlertPresentException e)
{
// no alert message
}
A future enhancement to webdriver will be to throw an exception on any command if an alert is present.
The current implementation of SwitchTo().Alert() causes a small sleep delay because it has to wait for the browser to propagate the events for the alert window to appear (IIRC it's 300ms).
For now what you have is your best bet for when you don't know for sure if an alert will appear on the page. In the future you should be able to catch a different exception for regular commands that don't have the delay built in.
精彩评论