Selenium 2 - Javascript Alert triggered by Back button blocks driver.navigate().back()
I need to handle a javascript alert which is triggered when the back button is pressed. i.e.:
- Go to our site
- Click back
- Javascript alert will pop up
Dismiss alert
I implemented a test which works fine in firefox but in Internet Explorer (7), the driver.navigate.back(开发者_如何学C) method blocks until the alert is manually removed.
Has anyone come across this before? Any hints would be highly appreciated :)
I am using RemoteWebDriver for this test.
Mark
If you are using RemoteWebDriver you can use the RemoteTargetLocator inner class, it implements methods to handle alerts:
driver.switchTo().alert().accept()
I managed to solve this by sending the following javascript command instead of using navigate().back():
driver.executeScript(javascript: setTimeout(\"history.go(-1)\", 2000));
精彩评论