我创建了硒离子测试。我想在intellij想法上运行Java文件。我像这样准备了pom.xml,但是在运行测试时遇到了问题。

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版本。
这将帮助您防止任何意外错误

与在其他依赖项中使用的相同版本,请在下面更改为3.141.59

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


您遇到的另一件事是错误,如下所示:


  没有这样的元素:无法找到元素:{“ method”:“ css
  选择器”,“选择器”:“。ion-navicon”}(会话信息:
  chrome = 76.0.3809.132)


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

10-01 03:45
查看更多