gpt4 book ai didi

java - Selenium 测试 Java Maven 依赖关系

转载 作者:行者123 更新时间:2023-11-30 05:26:22 25 4
gpt4 key购买 nike

我在 selenium ide 上创建了测试。我想在intellij idea上运行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 版本。它将帮助您防止任何意外错误

将以下依赖项更改为今天的最新版本: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":"cssselector","selector":".ion-navicon"} (Session info:chrome=76.0.3809.132)

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

关于java - Selenium 测试 Java Maven 依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58505362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com