通过Selenium启动浏览器时获取异常java.lang.ClassNotFoundException:org.openqa.selenium.MutableCapabilities

时间:2019-06-22 18:56:00

标签: java maven selenium selenium-webdriver selenium-chromedriver

IntelliJ尝试启动Chrome浏览器时出现上述异常。

我正在Ubuntu 16.04上运行此代码,并且我已经尝试过更新浏览器并为ChromeDriver使用特定的jar。

启动浏览器的代码:

WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();

POM.xml:

<dependencies>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>3.141.59</version>
    </dependency>


    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>2.2.5</version>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version>
    </dependency>

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.14.3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.17</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.17</version>
    </dependency>

    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>3.1.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.0</version>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.6</version>
    </dependency>


    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-api</artifactId>
        <version>2.53.1</version>
        <scope>test</scope>
    </dependency>


    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.5</version>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-remote-driver</artifactId>
        <version>2.53.1</version>
    </dependency>

2 个答案:

答案 0 :(得分:1)

您正在使用的硒(2.53.1)的较旧版本与最新的chrome驱动程序二进制文件不兼容。

请参阅POM的以下部分:

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-api</artifactId>
        <version>2.53.1</version>
        <scope>test</scope>
    </dependency>

撰写本文时,Selenium的当前Java版本为3.141.59(请查看https://www.seleniumhq.org/download/以了解最新版本)。

您需要更新到最新版本的Selenium。

答案 1 :(得分:0)

在您的pom地方作为财产:

<properties>
    <selenium.version>3.5.3</selenium.version>
</properties>

然后,在使用硒版本的每个依赖项中,只需替换为属性引用,如下所示:

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>${selenium.version}</version>
    </dependency>