使用 webdriver selenium 处理子菜单项 [英] handling submenu item with webdriver selenium
问题描述
我想使用默认不可见的 selenium webdriver 单击子菜单项.它在 mousehover 上变得可见.我尝试了一些代码,它给出了如下所示的错误
I want to click submenu item using selenium webdriver which is invisible bydefault. It becomes visible on mousehover . I tried with some code and it is giving error as shown below
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: 元素当前不可见,因此可能无法与之交互.
代码如下:
Actions actions = new Actions(driver);
WebElement menuHoverLink = driver.findElement(By.linkText("RENT"));
//WebElement menuHoverLink = driver.findElement(By.className("current"));
actions.moveToElement(menuHoverLink);
WebElement subLink = driver.findElement(By.cssSelector("a[href='nemc.com/rentals/easy-rent']"));
actions.moveToElement(subLink);
actions.click();
actions.perform();
推荐答案
使用 Actions 类在菜单项上进行鼠标悬停,然后单击子菜单选项.您可以参考 Actions 类以获取可用方法的概述和一个很好的帮助 此处a> 了解如何使用这些交互.
Use the Actions class to do a mousehover on your menu item and then a click on the submenu option. You can refer to Actions class to get an overview of the methods available and a good help here to understand how to use these interactions.
Actions actions = new Actions(driver); WebElement menuHoverLink = driver.findElement(By.linkText("RENT"));
actions.moveToElement(menuHoverLink).perform();
driver.findElement(By.cssSelector("a[href='nemc.com/rentals/easy-rent']")).click();
我希望你的定位是正确的..你可能想使用一个[contains(@href,'nemc.com/rentals')'
I am hoping your locatros are correct..you might want to use a[contains(@href,'nemc.com/rentals')'
这篇关于使用 webdriver selenium 处理子菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!