首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么在Windows中工作的相同的代码在CentOS 7中不起作用?

问为什么在Windows中工作的相同的代码在CentOS 7中不起作用?
EN

Stack Overflow用户
提问于 2022-11-28 21:47:28
回答 1查看 45关注 0票数 -2

基本上,我有一个使用Selenium (Chromedriver)从网站获取数据的java程序。

相同的java程序在windows上运行时没有任何错误,这时我还没有犯任何错误。在CentOS 7中,它可以工作,但会抛出一些错误&这很奇怪。

错误:

代码语言:javascript
复制
Exception in thread "Thread-6" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code                                  500. Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that C                                 hrome has crashed.)
Host info: host: 'instance-20221128-2304', ip: '10.0.0.105'
Build info: version: '4.6.0', revision: '79f1c02ae20'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1160.76.1.el7.x86_64', java.version: '1.8.0_352'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless], exten                                 sions: []}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless], extensions: [                                 ]}}}]
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:146)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:101)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:541)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
        at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:101)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:81)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:70)
        at org.hinoob.bot.BangerFM.fetch(BangerFM.java:55)
        at org.hinoob.bot.BangerFM.lambda$startLoop$0(BangerFM.java:26)
        at java.lang.Thread.run(Thread.java:750)`

我按照本指南安装了以下内容:https://www.usessionbuddy.com/post/How-To-Install-Selenium-Chrome-On-Centos-7/

我在CentOS中的谷歌铬版: google 107.0.5304.121

我还没试过什么,因为我不知道该尝试什么。我希望它能像在Windows中一样工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-29 02:57:07

Selenium 4.6.0发布!selenium引入Selenium Manager,现在您不需要添加驱动程序路径或任何东西。现在selenium自动更新驱动程序。

在您的情况下,我想这个问题是因为铬驱动程序兼容性问题。

更新您的selenium版本,如果它是一个maven项目,那么添加以下依赖项

代码语言:javascript
复制
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.6.0</version>
</dependency>

然后删除系统属性,如果您手动添加色度驱动程序路径,希望您的问题能够解决。

另一个导致打开浏览器问题的检查点

如果服务器是无头的,请确保在服务器/pc --headless

  • Add

  • 中安装了
  1. ,然后添加参数
  2. ,禁用GPU参数

参考https://www.selenium.dev/blog/2022/introducing-selenium-manager/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74606814

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档