Home > Software engineering >  Why does the same code what works in Windows, does not in CentOS 7?
Why does the same code what works in Windows, does not in CentOS 7?

Time:11-30

Basically, I have a java program what gets data from websites using Selenium (Chromedriver)

The same java program works without any errors on windows, that's when I haven't done any mistakes. In CentOS 7, it works, but throws a few errors & is weird.

Errors:

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)`

I've followed this guide to install the things: https://www.usessionbuddy.com/post/How-To-Install-Selenium-Chrome-On-Centos-7/

My google chrome version in CentOS: Google Chrome 107.0.5304.121

I didn't try anything yet, since I don't know what to try. I expected it to work same as in Windows.

CodePudding user response:

Selenium 4.6.0 Released! selenium Introducing Selenium Manager Now you dont need to add driver path or anything. Now selenium automatically update driver.

In your case i guess this issue is for chrome driver compatibility issues.

Update your selenium version, If its a maven project then add following dependency

<!-- 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>

And then remove system property if you added chromedriver path manually, Hope your problem will solved.

Another checkpoint which cause issue for open browser

  1. Make sure chrome is installed in the server/pc
  2. If server is headless then add argument --headless
  3. Add disable GPU argument

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

  • Related