0

Platform: Ubuntu 22.04 Java version: 17.0.7 Selenium: 4.10.0 Chrome and chromedriver version: 114.0.5735

  1. Create ChromeDriver with google chrome and chromedriver installed in host system

I tested the google chrome connection by this:

System.setProperty("webdriver.chrome.driver", chromeWebdriver);

ChromeOptions co = new ChromeOptions();
co.addArguments("--remote-allow-origins=*");
co.addArguments("--headless=new");
co.addArguments("--allowed-ips=127.0.0.1");
co.addArguments("--no-sandbox");
co.addArguments("--disable-setuid-sandbox");
co.addArguments("--remote-debugging-port=9222");
co.addArguments("--disable-dev-shm-usage");
co.addArguments("--disable-extensions");
co.addArguments("--disable-gpu");

driver = new ChromeDriver(co);
driver.get(W3SCHOOL_URL);
logger.info("test_chrome_by_system_property page title: {}", driver.getTitle());
  1. Create ChromeDriver with google chrome and chromedriver Dockerfile
## install google chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN apt-get -y update
RUN apt-get install -y google-chrome-stable

## install chrome webdriver
RUN wget -q -O $APP_DIR/chromedriver_$CHROME_DRIVER_VERSION_linux64.zip https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip
RUN unzip $APP_DIR/chromedriver_$CHROME_DRIVER_VERSION_linux64.zip -d /usr/bin/
RUN chmod +x /usr/bin/chromedriver
RUN rm -rf $APP_DIR/chromedriver_$CHROME_DRIVER_VERSION_linux64.zip

I checked the google chrome and chromedriver status on docker, return this:

docker exec -it my_docker_container_name google-chrome --help Google Chrome 114.0.5735.198 docker exec -it my_docker_container_name chromedriver --version ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052})

But always the same error occured.

Exception:
2023-07-12 13:15:05 [main] INFO  c.e.maventest.MavenTestApplication.logStarted(61) - Started MavenTestApplication in 18.556 seconds (JVM running for 21.414)
Starting ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}) on port 45237
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[1689167707.191][SEVERE]: bind() failed: Cannot assign requested address (99)
ChromeDriver was started successfully.
2023-07-12 13:15:12 [main] ERROR c.e.m.service.SpringSeleniumRunner.run(101) - SpringSeleniumRunner exception: {}
java.lang.Exception: org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
  (unknown error: unable to discover open pages)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '4.1.4', revision: '535d840ee2'
System info: host: '247af48ef4bc', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit-pr', java.version: '17.0.7'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, --headless=new, --allowed-ips=127.0.0.1, --no-sandbox, --disable-setuid-sandbox, --remote-debugging-port=9222, --disable-dev-shm-usage, --disable-extensions, --disable-gpu], extensions: []}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, --headless=new, --allowed-ips=127.0.0.1, --no-sandbox, --disable-setuid-sandbox, --remote-debugging-port=9222, --disable-dev-shm-usage, --disable-extensions, --disable-gpu], extensions: []}}}]
    at com.example.maventest.service.SpringSeleniumRunner.testChromeBySystemProperty(SpringSeleniumRunner.java:60)
    at com.example.maventest.service.SpringSeleniumRunner.run(SpringSeleniumRunner.java:98)
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:759)
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:749)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
    at com.example.maventest.MavenTestApplication.main(MavenTestApplication.java:13)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
  (unknown error: unable to discover open pages)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '4.1.4', revision: '535d840ee2'
System info: host: '247af48ef4bc', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit-pr', java.version: '17.0.7'
Dhamore
  • 1
  • 2

1 Answers1

0

You need to consider a couple of things:

  • --disable-gpu was originally intended to be used only in environment. The system being a non-windows system you need to drop the argument.
  • --remote-allow-origins=* is no more mandatory with Chrome and ChromeDriver version: 114.0. So you can drop it.
  • --disable-extensions is no more effective in modern browsers. So you can drop it.
  • --no-sandbox isn't mandatory unless you are executing you test as a root user. So you can drop it.
  • disable-dev-shm-usage and --disable-setuid-sandbox isn't effective unless you are using the --no-sandbox argument. So you can drop it.

Making the above mentioned adjustments execute your code.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352