问题
I have been trying all possible answers that were provided for similar Query.
My lay-out Structure of the Menu:
MainMenu1 , Manimenu2.... etc Under Each Mainmenu
Submenu1>Item1, Item2, Item3
Submenu2>Item1, Item2, Item3
Submenu3>Item1, Item2, Item3
To get to Item1 or Item2 or Item3, we have to move the mouse over and hover it over Mainmenu1>submenu1 and then click Item2
I was able to use mouse-hover command and get it open the Mainmenu but unable to get past it.
Any suggestions Please?
Thankyou.
回答1:
After mouse-hovering mainmenu1
you need to find submenu1
and then perform mouse-hover
Actions builder = new Actions(driver);
WebElement mainmenu1 = driver.findElement(By.xxxxx());
builder.moveToElement(mainmenu1 ).build().perform();
Thread.sleep(500); //add a wait
WebElement submenu1= driver.findElement(By.xxxxx()); //Find the submenu
builder.moveToElement(submenu1).click().build().perform();
Thread.sleep(500);
回答2:
Try this, I think it will help you
new Actions(wd)
.moveToElement(
wd.findElement(By
.linkText("MainMenu1")))
.build().perform();
Thread.sleep(500);
wd.findElement(By.linkText("Item1")).click();
来源:https://stackoverflow.com/questions/26141053/how-to-select-2nd-level-submenu-in-selenium-webdriver-with-java