Selenium 测试 Java maven 依赖项

Selenium test Java maven dependencies

我在 selenium ide 上创建了测试。我想 运行 java intellij idea 上的文件。我像那样准备了 pom.xml 但我在 运行ning 测试中遇到问题。

dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>htmlunit-driver</artifactId>
        <version>2.33.2</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.12.0</version>
    </dependency>
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>3.7.1</version>
    </dependency>
</dependencies>

当我运行它时,测试失败

Starting ChromeDriver 2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706) on port 28288
Only local connections are allowed.
paź 22, 2019 3:17:24 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":".ion-navicon"}
  (Session info: chrome=76.0.3809.132)
  (Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 4.15.0-65-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html

我应该如何在 Intellij Idea 上 运行 它?

对 selenium-java、selenium-server 等使用相同的 selenium 版本。 它将帮助您防止任何意外错误

将以下依赖项更改为今天的最新版本 4.1.3。您可以在 URL:

中找到最新版本

https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java

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

您遇到的另一件事如下:

no such element: Unable to locate element: {"method":"css selector","selector":".ion-navicon"} (Session info: chrome=76.0.3809.132)

这意味着您的定位器不正确或尚未准备好。检查您的定位器并在要定位的元素之前添加等待