-
Notifications
You must be signed in to change notification settings - Fork 103
Open
Description
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:
- Execute a test on a page where the menu closes when the
onblurevent is triggered. - 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
Labels
No labels