开发者

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.:

  1. Go to our site
  2. Click back
  3. Javascript alert will pop up
  4. 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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜