【问题标题】:How to select 2nd Level SubMenu in Selenium WebDriver with Java如何使用 Java 在 Selenium WebDriver 中选择二级子菜单
【发布时间】:2014-10-01 12:09:46
【问题描述】:

我一直在尝试为类似查询提供的所有可能答案。

我的菜单布局结构:

MainMenu1 , Manmenu2.... 等 在每个主菜单下

   Submenu1>Item1, Item2, Item3
   Submenu2>Item1, Item2, Item3
   Submenu3>Item1, Item2, Item3

要到达 Item1 或 Item2 或 Item3,我们必须将鼠标移到 Mainmenu1>submenu1 上,然后单击 Item2

我能够使用鼠标悬停命令并打开主菜单,但无法通过它。

有什么建议吗?

谢谢。

【问题讨论】:

  • 您是否使用了 AdvancedUserInteractions,如果是,那么发生了什么?请告诉我们您是如何尝试处理此问题的。

标签: selenium selenium-webdriver


【解决方案1】:

鼠标悬停mainmenu1后,需要找到submenu1,然后进行鼠标悬停

        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);

【讨论】:

  • Actions a = new Actions(driver); WebElement menuHoverLink = driver.findElement(By.cssSelector("#admin")); a.moveToElement(menuHoverLink); WebElement subLink = driver.findElement(By.cssSelector(".companyinfo")); a.moveToElement(子链接);线程.sleep(5000L); WebElement subLink3 = driver.findElement(By.className("companyinfo")); a.moveToElement(subLink3); a.点击(); a.build().perform();线程.sleep(5000L); WebElement subLink4 = driver.findElement(By.cssSelector("#admin >ul>li:nth-child(1)>ul>li:nth-child(3)>a>span")); actions.moveToElement(subLink4); a.点击(); a.build().perform();
  • 我可以看到它悬停打开;但没有点击打开;
  • 等待它并点击它
【解决方案2】:

试试这个,我想它会帮助你

 new Actions(wd)
    .moveToElement(
            wd.findElement(By
                    .linkText("MainMenu1")))
    .build().perform();
 Thread.sleep(500);
 wd.findElement(By.linkText("Item1")).click();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-20
    相关资源
    最近更新 更多