w3c / w3c/webdriver

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

Open
#1,240 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Element Click
Dominant language
HTML
Stars
718
Forks
228
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the two HTML examples and the Selenium Java call sequence, focusing on how click-triggered navigation interacts with confirmation dialogs and alert acceptance. No repository file or test is named; done means defining and validating synchronous navigation behavior for indirect JavaScript-triggered link clicks without breaking cases where navigation does not occur.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, javascript
Domain
api, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.