Skip to content

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

Open
@joshlandin

Description

@joshlandin

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions