w3c / webdriver

Remote control interface that enables introspection and control of user agents.
https://w3c.github.io/webdriver/
Other
678 stars 192 forks source link

Link clicks resulting in navigation, but intercepted by JavaScript (e.g. confirmation dialogs in onclick) should block during navigation #1240

Open joshlandin opened 6 years ago

joshlandin commented 6 years ago

Using: Selenium 3.10.0, Gecko 0.19.1-64bit, Firefox 58.0.2 (Native Events disabled)

I struggled with whether this issue is most relevant to Selenium, Geckodriver, WebDriver, or Marionette/Firefox, but ultimately settled here.

Today, clicking a link that results in browser navigation is a blocking operation. I realize that we may not always get this right, but in most cases, this is true. For example:

HTML:
    <a href="/resubmit.htm" id="resubmit">Resubmit</a>
TEST:
    driver.findElement(By.id("resubmit")).click();   // Waits for the navigation to resubmit.htm.   
    WebElement element = driver.findElement(By.cssSelector(".somethingOnSubsequentPage"));
    // Success!

However when a confirmation dialog determining whether navigation is triggered is added to the link, the click()/accept() no longer block on the navigation:

HTML:
    <a href="/resubmit.htm" id="resubmit" onclick="javascript:return confirm('Are you sure?');">Resubmit</a>
TEST:
    driver.findElement(By.id("resubmit")).click();     
    driver.switchTo().alert().accept(); // Does not wait for navigation to resubmit.htm.
    WebElement element = driver.findElement(By.cssSelector(".somethingOnSubsequentPage"));
    // Fail. :(

This request is to make link navigation a synchronous event (from a testing perspective), even when it results from a click() indirectly via JavaScript. Hopefully the approach would address the majority of cases, even if it cannot solve all.

joshlandin commented 6 years ago

Duplicate of https://github.com/w3c/webdriver/issues/1166?

whimboo commented 6 years ago

No, it's not a duplicate.

Currently the spec only covers handling of alerts before the actual command is getting performed. If like in this case a navigation request causes an alert to be opened, we indeed would have to define an appropriate handling of alerts in waiting-for-the-navigation-to-complete.