Skip to content

BUG: Menu closure on onblur event causes element not found error after AxeBuilder.analyze() execution #532

@d-v

Description

@d-v

Describe the bug
The AxeBuilder.analyze() method opens a new tab, causing menus that rely on the onblur event to close. As a result, the element within the menu cannot be found.

Environment Happening In

  • Production
  • QA
  • Dev

To Reproduce
Steps to reproduce the behavior:

  1. Execute a test on a page where the menu closes when the onblur event is triggered.
  2. Attempt to locate and click the menu element.
this.driver.get("file:///C:/projects/selenium/sample.html");
this.driver.findElement(By.id("menuButton")).click();
Results axeResults = this.axeBuilder.analyze(this.driver);
this.driver.findElement(By.id("menu-item")).click();

Expected behavior
The test should continue successfully, locating and clicking the menu item button.

Actual behavior
Due to the menu closing on the onblur event, the subsequent step of clicking the element within the menu fails.

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#menu\-item"}
  (Session info: chrome=119.0.6045.124)

Related Tickets
#391

Desktop (please complete the following information):

  • Product: axe-core selenium
  • Product Version: 4.27.0
  • OS: Windows 10
  • Browser Chrome
  • Browser Version v119

Additional context
Sample page below that has the issue

<!DOCTYPE html>
<html lang="en">
  <body>
    <button id="menuButton">Open Menu</button>
    <script>
      const menuButton = document.getElementById('menuButton');
      let menu = null;

      function createMenu() {
        menu = document.createElement('div');
        menu.id = 'menu';
        menu.innerHTML = `
          <a href="https://www.example.com" target="_blank" id="menu-item">Open Example.com in New Tab</a><br>
          <a href="#">Menu Item 2</a>
        `;
        document.body.appendChild(menu);
      }

      function removeMenu() {
        if (menu) {
          menu.remove();
          menu = null;
        }
      }

      menuButton.addEventListener('click', () => {
        if (menu) removeMenu();
        else createMenu();
      });

      window.addEventListener('blur', () => removeMenu());
    </script>
  </body>
</html>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions