How to select 2nd Level SubMenu in Selenium WebDriver with Java

萝らか妹 提交于 2021-01-28 09:22:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!