Java moveToElement()执行悬停操作

Java moveToElement()执行悬停操作,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,有人能帮忙说明为什么这不起作用吗 页面对象: import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.CacheLookup; import org.openqa.selenium.support.FindBy; import org

有人能帮忙说明为什么这不起作用吗

页面对象:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;

    public class NavBarPO {

    WebDriver driver;
    Actions action;

    public NavBarPO(WebDriver driver){
        this.driver = driver;
        PageFactory.initElements(driver, this);
        action = new Actions(driver);
    }
        @CacheLookup
        @FindBy(how = How.CSS, using = "li.menu-item.menu-item-type-taxonomy.menu-item-object-wpsc_product_category.menu-item-has-children.has_children > a")
        private WebElement product_Category;    

        public void hover_Product_Category(){
            action.moveToElement(product_Category);
        }      
}
测试:


nav.hover\u Product\u Category()。当我使用
.click()
而不是
.moveToElement()
时,会单击元素并显示我想要的下拉列表,因此选择器是正确的。

您需要调用
Actions
类方法上的
perform()

public void hover_Product_Category(){
    action.moveToElement(product_Category).perform();
}

您需要调用
Actions
类方法上的
perform()

public void hover_Product_Category(){
    action.moveToElement(product_Category).perform();
}

功能
moveToElement
FirefoxDriver
中无法正常工作。解决方案是将测试更改为
ChromeDriver
。如果您需要测试Firefox,您可以用
单击
替换
moveToElement
,功能
moveToElement
FirefoxDriver
中无法正常工作。解决方案是将测试更改为
ChromeDriver
。如果您需要测试Firefox,您可以将
moveToElement
替换为
click

I include
.perform()
现在测试抛出异常
org.openqa.selenium.unsupportedCommand异常:POST/session/d33e2dc4-2b3b-4f1b-a22d-20673c2445b7/moveto与已知命令不匹配
@GabrielAbel异常发生在哪里?在
action.moveToElement(产品类别).perform()上?正是@Guy。当我包含
.perform()
时。当它只是
action.moveToElement(产品类别)时此异常未发生。@GabrielAbel如何初始化
操作
?您使用的导入是什么?@GabrielAbel我看到您使用的是
FirefoxDriver
。这是一个好主意。我们将FireFox降级为45.0版。我加入了
.perform()
,现在测试抛出异常
org.openqa.selenium.unsupportedCommand异常:POST/session/d33e2dc4-2b3b-4f1b-a22d-20673c2445b7/moveto与已知命令不匹配
@GabrielAbel异常发生在哪里?在
action.moveToElement(产品类别).perform()上?正是@Guy。当我包含
.perform()
时。当它只是
action.moveToElement(产品类别)时此异常未发生。@GabrielAbel如何初始化
操作
?您使用的导入是什么?@GabrielAbel我看到您使用的是
FirefoxDriver
。这是一个好主意。我们将FireFox降级为45.0版。