Back to All Scenarios
Scenario 24 of 100
Mouse Actions
Intermediate
Hovering on a Multi-Level Dropdown Menu
πScenario Overview
Hovering on a Multi-Level Dropdown Menu
Key Takeaways & Cheat Sheet
- βInstantiate Actions class to chain complex hover sequences
- βWait explicitly for secondary and tertiary submenu visibility after hovers
- βUse moveToElement() sequentially on each intermediate navigation link
- βAdd short build().perform() execution boundaries for each hover step
Short Direct Answer
Multi-level dropdown menus require sequential hover actions to reveal nested links. To automate this, hover over the parent element using the `Actions` class, wait explicitly for the next submenu to be visible, hover over the submenu element, and repeat this pattern before clicking your target element.
β οΈ Senior Warning (Red Flag)
Do not chain all hovers into a single continuous moveToElement actions block without waits. The UI needs time to animate submenus; clicking immediately will result in NoSuchElementException.
π‘ STAR Deep Dive Explanation & Pro Tip
Splitting actions.perform() operations and adding intermediate explicit visibility waits is key to stabilizing multi-level navigation selectors.
SeleniumAutomation.java
Selenium 4 + Javaimport org.openqa.selenium.interactions.Actions;
Actions actions = new Actions(driver);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
// β
Step 1: Hover over parent menu
WebElement mainCategory = driver.findElement(By.id("nav-electronics"));
actions.moveToElement(mainCategory).perform();
// β
Step 2: Wait for submenu and hover over secondary link
WebElement subCategory = wait.until(
ExpectedConditions.visibilityOfElementLocated(By.linkText("Computers"))
);
actions.moveToElement(subCategory).perform();
// β
Step 3: Wait for tertiary link and click it
WebElement targetLink = wait.until(
ExpectedConditions.elementToBeClickable(By.linkText("Laptops"))
);
targetLink.click();