Reputation: 35
Not able to click on submenu in our application. As per the attached picture. I am trying to achieve below scenario steps:
Menu 1
<Item 3>
Sub Item 2
I have tried below code and not able to click on Sub Item 2, Because the issue is when selenium is trying to click on Sub Item 2, the focus/cursor/mouseover changed from Item 3 to Item 1. And 2nd sub item present in Item 1 got clicked.
driver.findElement(By.linkText("Menu 1")).click();
WebElement item3 = driver.findElement(By.linkText("<Item 3>"));
Actions action = new Actions(driver);
action.moveToElement(item3).pause(Duration.ofSeconds(1)).build().perform();
action.moveToElement(driver.findElement(By.linkText("<sub Item2>")))
.click().build().perform();`
Please help me with the solution to handle this situation.
Upvotes: 0
Views: 108
Reputation: 193148
As per your steps :
Here is the pseudo code block :
driver.findElement(By.linkText("Menu 1")).click();
WebElement item3 = driver.findElement(By.linkText("<Item 3>"));
Actions action = new Actions(driver);
action.moveToElement(item3).build().perform();
driver.findElement(By.linkText("<sub Item2>")).click();
Upvotes: 0
Reputation: 5347
You can make it as chained actions. It may work for you.
WebElement menu1 = driver.findElement(By.linkText("Menu 1"));
WebElement item3 = driver.findElement(By.linkText("<Item 3>"));
Actions action = new Actions(driver);
action.click(menu1).moveToElement(item3).click(driver.findElement(By.linkText("<sub Item2>"))).build.perform();
Upvotes: 1