Java 指针操作缺少类型参数或类型参数无效-Selenium

Java 指针操作缺少类型参数或类型参数无效-Selenium,java,eclipse,selenium-webdriver,Java,Eclipse,Selenium Webdriver,我在运行程序时收到下面提到的错误消息 错误:指针操作缺少类型参数或类型参数无效 我试图点击子菜单,鼠标悬停在主菜单上后会显示子菜单 代码如下: public class ActionKeywords { WebDriver driver = new FirefoxDriver(); @Test public void openBrowser(){ driver.get("https://www.levissima.it/"); drive

我在运行程序时收到下面提到的错误消息

错误:指针操作缺少类型参数或类型参数无效

我试图点击子菜单,鼠标悬停在主菜单上后会显示子菜单

代码如下:

public class ActionKeywords {
    WebDriver driver = new FirefoxDriver();

    @Test
    public void openBrowser(){
        driver.get("https://www.levissima.it/");
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.manage().window().maximize();
    }
    @Test
    public void verify_Menus(){

        WebElement mainMenu = driver.findElement(By.xpath("//ul[@id='menu-main']/li/a"));

        WebElement subMenu = driver.findElement(By.xpath("//a[contains(text(),'Impegno Per La Natura')]"));
        Actions action = new Actions (driver);
        action.moveToElement(mainMenu).perform();
        action.click(subMenu).perform();
    }
}

请协助

实现这一点的一个更好的方法是:

    Actions action = new Actions (driver);
    action.moveToElement(mainMenu).moveToElement(subMenu).click().build().perform();

这称为动作链接。

使用Selenium 3.4.0要使用Mozilla Firefox浏览器53.x,您需要从下载最新的geckodriver。将其保存在您的机器中,并提供壁虎河的绝对路径。通过对您自己的代码进行一些简单的调整,该代码可以很好地执行

WebDriver driver;

@BeforeTest
public void setup()
{
    System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
    DesiredCapabilities dc = DesiredCapabilities.firefox();
    dc.setCapability("marionette", true);
    driver =  new FirefoxDriver(dc);
    driver.manage().window().maximize();
}

@Test
public void openBrowser(){
    driver.get("https://www.levissima.it/");
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    driver.manage().window().maximize();
}
@Test
public void verify_Menus(){

    WebElement mainMenu = driver.findElement(By.xpath("//ul[@id='menu-main']/li/a"));

    WebElement subMenu = driver.findElement(By.xpath("//a[contains(text(),'Impegno Per La Natura')]"));
    Actions action = new Actions (driver);
    action.moveToElement(mainMenu).perform();
    action.click(subMenu).perform();
}
输出为:

PASSED: openBrowser
PASSED: verify_Menus

===============================================
    Default test
    Tests run: 2, Failures: 0, Skips: 0
===============================================

如果这回答了您的问题,请告诉我。

我今天遇到了这个错误,并使用另一个geckodriver版本解决了它。在这种情况下(Firefox52+Selenium 3.8.0),geckodriver 0.15解决了这个问题

这不是我第一次被迫下载并尝试不同版本的Firefox/Geckodriver/Selenium

默认情况下,下载最新的geckodriver不会解决问题。根据您的Firefox和geckodriver版本,您可能需要一个旧版本,因此,不要犹豫,自己尝试,而不是仅仅获得最新版本,希望它能神奇地工作


我真的建议你在发疯之前尝试不同的壁虎河。

哪一行会让你犯这个错误;添加完整的错误堆栈跟踪。您在哪一行看到错误?请提供完整的错误堆栈trace.org.openqa.selenium.InvalidArgumentException:指针操作生成信息的类型参数缺失或无效:版本:'3.3.1',版本:'5234b325d5',时间:'2017-03-10 09:10:29+0000'系统信息:主机:'M3B-D-543T2D3',ip:'192.168.91.1',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',java.version:'1.8.0_111'是。库沙尔。但是,我仍然得到了与org.openqa.selenium.InvalidArgumentException相同的错误:指针actionimport java.util.concurrent.TimeUnit的类型参数缺失或无效;导入java.util.List;导入org.openqa.selenium.By;导入org.openqa.selenium.WebDriver;导入org.openqa.selenium.WebElement;导入org.openqa.selenium.firefox.FirefoxDriver;导入org.openqa.selenium.interactions.Actions;导入org.openqa.selenium.remote.DesiredCapabilities;导入org.openqa.selenium.support.ui.WebDriverWait;导入org.testng.annotations.BeforeTest;导入org.testng.annotations.Test;这解决不了任何问题。MoveTo仅在自动化一些新的、奇特的javascript UI时才起作用,这些UI要求元素的焦点是“可点击的”。这个问题是版本之间的错误。您必须在Firefox和Selenium集合中使用适当的geckodriver。至少一个应该可以工作。配置失败:@BeforeTest setup java.lang.ClassCastException:org.openqa.selenium.remote.service.DriverCommandExecutor不能强制转换为org.openqa.selenium.firefox.FirefoxDriver$lazycommandexecutor。您使用的是哪个版本的Selenium?2.你在用gecko驱动程序吗?3.如果是,是哪个版本?4.您的Mozilla Firefox浏览器版本是什么?Selenium 3.3.1 Firefox 53.0Done!再次感谢:)