Selenium webdriver 如何使用SeleniumWebDriver单击子菜单项。。。?

Selenium webdriver 如何使用SeleniumWebDriver单击子菜单项。。。?,selenium-webdriver,Selenium Webdriver,我只想使用SeleniumWebDriver从菜单下拉列表中单击一个子菜单。 我尝试了几个例子,但不起作用。您能给出单击子菜单项的逻辑吗。要执行“鼠标悬停”操作,您需要一次连接所有要实现的操作 对于actions对象,您应该首先移动到下拉列表,然后移动到下拉列表项并单击它 下面是我尝试执行鼠标悬停的示例代码 //Move to the Dropdown Actions actions = new Actions(driver); WebElement dropdown = wai

我只想使用SeleniumWebDriver从菜单下拉列表中单击一个子菜单。
我尝试了几个例子,但不起作用。您能给出单击子菜单项的逻辑吗。

要执行“鼠标悬停”操作,您需要一次连接所有要实现的操作

对于actions对象,您应该首先移动到下拉列表,然后移动到下拉列表项并单击它

下面是我尝试执行鼠标悬停的示例代码

//Move to the Dropdown    
Actions actions = new Actions(driver);
    WebElement dropdown = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("dropdown")));
actions.moveToElement(dropdown);

//Wait for the Dropdown Item to become available then click it    
    WebElement dropdownitem = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("dropdownitem")));
    actions.moveToElement(dropdownitem);
    actions.click().build().perform();

请添加您的代码。嗨,事实上我是新加入selenium的。我只是从网络上复制了代码并尝试了一下。如果您是selenium的新手,那就好了。在此处共享复制的代码,以便用户可以分析并提供带有解释的解决方案。要共享代码,请编辑您的问题并将其添加到那里。避免在注释中给出代码: