我每年都会运行几次测试,有时必须更新我的 chromedriver 以匹配我的 Google Chrome 版本。今天是我尝试运行这些测试的日子之一,除了这次更新我的 chromedriver 后,测试仍然不起作用,并且我收到了这些警告和错误。
Starting ChromeDriver 123.0.6312.105 (399174dbe6eff0f59de9a6096129c0c827002b3a-refs/branch-heads/6312@{#761}) on port 53767
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Apr 10, 2024 4:35:11 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected upstream dialect: W3C
Apr 10, 2024 4:35:11 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 123, so returning the closest version found: a no-op implementation
Apr 10, 2024 4:35:11 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Unable to find CDP implementation matching 123.
Apr 10, 2024 4:35:11 PM org.openqa.selenium.chromium.ChromiumDriver lambda$new$3
WARNING: Unable to find version of CDP to use for . You may need to include a dependency on a specific version of the CDP using something similar to `org.seleniumhq.selenium:selenium-devtools-v86:4.4.0` where the version ("v86") matches the version of the chromium-based browser you're using and the version number of the artifact is the same as Selenium's.
16:35:43.557 [main] ERROR -
16:35:43.561 [main] ERROR - Test failed at step: When Sample.y4m is tested
16:35:43.561 [main] ERROR - Failed to get a result in time. Exception thrown Expected condition failed: waiting for presence of element located by: By.cssSelector: pre[id="resultText"] li (tried for 30 second(s) with 500 milliseconds interval)
Selenium 在我的 pom.xml 文件中被引用,如下所示:
<testPlanLibraries>
<artifact>org.skyscreamer:jsonassert:jar:1.5.0</artifact>
<artifact>org.seleniumhq.selenium:selenium-java:3.141.59</artifact>
<artifact>org.seleniumhq.selenium:selenium-api:jar:3.141.59</artifact>
</testPlanLibraries>
我尝试降级我的谷歌浏览器版本,但它没有显示在我的添加或删除程序中以卸载。我尝试从程序目录中删除它并安装旧版本,但这不起作用。我想我需要在注册表中删除它的一些残留物,但我真的不想这样做。所以我想我应该尝试接受这一点并尝试使用正确的硒来使其正常运行。但我不确定要使用哪个版本,如果是的话如何将其添加到 pom.xml 文件中。
代码中使用的版本(
3.141.59
)pom.xml
太旧了。使用当前最新的 selenium 版本进行 Java 绑定,即 v4.19.1
。
只需将 xml 中的
3.141.59
替换为 4.19.1
,如下所示。
<testPlanLibraries>
<artifact>org.skyscreamer:jsonassert:jar:1.5.0</artifact>
<artifact>org.seleniumhq.selenium:selenium-java:4.19.1</artifact>
<artifact>org.seleniumhq.selenium:selenium-api:jar:4.19.1</artifact>
</testPlanLibraries>
另外,我不知道你的
<dependency>
中有没有pom.xml
。如果有,它应该如下所示:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.19.1</version>
</dependency>