Selenium webdrivermanager-在Linux服务器上运行时异常

发布于 2025-02-06 19:22:12 字数 1629 浏览 4 评论 0原文

我是硒的新手,还有一些问题。

我正在使用与硒有关的WebDrivermanager。这是我的代码:

WebDriverManager.chromedriver().setup();

当我在本地系统(Windows 10 OS)上运行代码时,一切都很好。当我在Linux服务器(Ubuntu 18.04,Tomcat 9)上运行代码作为Web应用程序时,我会得到以下例外:

io.github.bonigarcia.wdm.config.WebDriverManagerException: Exception reading resolution cache as a properties file
        at io.github.bonigarcia.wdm.cache.ResolutionCache.<init>(ResolutionCache.java:86)
        at io.github.bonigarcia.wdm.WebDriverManager.getResolutionCache(WebDriverManager.java:1490)
        at io.github.bonigarcia.wdm.WebDriverManager.clearResolutionCache(WebDriverManager.java:780)
        at io.github.bonigarcia.wdm.WebDriverManager.handleException(WebDriverManager.java:1263)
        at io.github.bonigarcia.wdm.WebDriverManager.manage(WebDriverManager.java:1060)
        at io.github.bonigarcia.wdm.WebDriverManager.setup(WebDriverManager.java:393)
....
Caused by: java.io.IOException: No such file or directory
        at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method)
        at java.base/java.io.File.createNewFile(File.java:1035)
        at io.github.bonigarcia.wdm.cache.ResolutionCache.<init>(ResolutionCache.java:75)

我使用的是Selenium 4.2.1和WebDriver 5.1.0。
在我们的Linux服务器上,我已经按照所述安装了Google Chrome 在这里。运行时,

google-chrome --version
-> Google Chrome 102.0.5005.115

我将获得显示的结果,因此我认为应该正确安装Chrome。 有人一个主意吗?

I am new to Selenium and having some issues.

I am using the WebDriverManager in connection with Selenium. This is my code:

WebDriverManager.chromedriver().setup();

When I run the code on my local system (Windows 10 OS), everything runs perfectly fine. When I run my code as a web application on our Linux Server (Ubuntu 18.04, Tomcat 9), I get the following exception:

io.github.bonigarcia.wdm.config.WebDriverManagerException: Exception reading resolution cache as a properties file
        at io.github.bonigarcia.wdm.cache.ResolutionCache.<init>(ResolutionCache.java:86)
        at io.github.bonigarcia.wdm.WebDriverManager.getResolutionCache(WebDriverManager.java:1490)
        at io.github.bonigarcia.wdm.WebDriverManager.clearResolutionCache(WebDriverManager.java:780)
        at io.github.bonigarcia.wdm.WebDriverManager.handleException(WebDriverManager.java:1263)
        at io.github.bonigarcia.wdm.WebDriverManager.manage(WebDriverManager.java:1060)
        at io.github.bonigarcia.wdm.WebDriverManager.setup(WebDriverManager.java:393)
....
Caused by: java.io.IOException: No such file or directory
        at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method)
        at java.base/java.io.File.createNewFile(File.java:1035)
        at io.github.bonigarcia.wdm.cache.ResolutionCache.<init>(ResolutionCache.java:75)

I am using Selenium 4.2.1 and Webdriver 5.1.0.
On our Linux server, I have installed Google Chrome as described here. When running

google-chrome --version
-> Google Chrome 102.0.5005.115

I get the shown result, so I think Chrome should be installed correctly.
Has anybody an idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卷耳 2025-02-13 19:22:12

似乎无法创建分辨率缓存,该缓存是默认情况下在以下路径中创建的属性文件:〜/.cache/selenium。您可以尝试手动创建该路径(尽管WebDriverManager在不存在时应该能够创建)。

无论如何,要正确调试,您需要检查WebDriverManager痕迹。为此,您需要包含一个记录配置文件(例如,例如 this )在您的项目类路径中。该文件的名称应为src/test/resources/logback-test.xml(如果仅想要测试的日志)或src/test/test/resources/logback.xml (如果您想要测试和应用程序代码的日志)。然后,您可以使用以下行将级别设置为跟踪

<logger name="io.github.bonigarcia" level="TRACE" />

有关使用SLF4J和LogBack登录的更多信息,您可以看到以下 tutorial

It seems it is failing to create the resolution cache, which is a properties files created by default in the following path: ~/.cache/selenium. You can try to create manually that path (although WebDriverManager should have been able to create when it does not exist).

In any case, to debug it properly, you need to check the WebDriverManager traces. For that, you need need to include a Logback configuration file (for example, like this) in your project classpath. The name of this file should be src/test/resources/logback-test.xml (if you want logs only for your tests) or src/test/resources/logback.xml (if you want logs for both tests and application code). Then, you can to use the following line to set the level to TRACE:

<logger name="io.github.bonigarcia" level="TRACE" />

For further info about logging with with SLF4J and Logback you can see the following tutorial.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文