My Chrome browser version is 119.0.6045.160. My chrome driver version is 119.0.6045.105.
My Selenium java version is 4.8.3.
I am doing web Scrapping with selenium. It runs without error in springboot. I have also set the binary path.
ChromeOptions options = new ChromeOptions();
options.setBinary("C:\Program Files\Google\Chrome\Application\chrome.exe");
WebDriver driver = new ChromeDriver(options);
However, when I run its docker image, I got the error :
Exception in thread "main" java.lang.reflect.InvocationTargetException
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:95)
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. Possible causes are invalid address of the remote server or browser start-up failure.
Host info: host: 'dd7e0e343e76', ip: '172.17.0.2'
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:561)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:229)
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:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:84)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:73)
at com.linggd.demo.Duldung2.myrun(Duldung2.java:64)
at com.linggd.demo.Htmltest3Application.main(Htmltest3Application.java:85)
... 8 more
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver process to start.
Build info: version: '4.8.3', revision: 'e5e76298c3'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.16.3-microsoft-standard-WSL2', java.version: '17.0.9'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:208)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:114)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
... 16 more
I think there might be some compatibility issue of chrome binary in docker with my chrome driver, so I specify the chrome version 119.0.6045.159-1 in my Dockerfile, but the error still exist.
Here is my Dockerfile:
FROM debian:bullseye-slim
WORKDIR /app
EXPOSE 8081
# Install required dependencies
RUN apt-get update && apt-get install -y openjdk-17-jre-headless libnss3 libxcb1
RUN apt-get install -y wget libgdk-pixbuf2.0-0 libnss3 libatk-bridge2.0-0 libcups2 libdrm2 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libxkbcommon-x11-0 libpangocairo-1.0-0 libasound2
ENV CHROME_VERSION "119.0.6045.159-1"
RUN set -ex &&
apt-get update -qqy &&
wget --no-check-certificate https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb &&
apt-get install -qqyf ./google-chrome-stable_${CHROME_VERSION}_amd64.deb &&
rm google-chrome-stable_${CHROME_VERSION}_amd64.deb
COPY target/springboot-aws-exe.jar /app/
COPY chromedriver.exe /app/chromedriver
ENTRYPOINT ["java", "-jar", "/app/springboot-aws-exe.jar"]
What have I done wrong? Any help is appreciated.
2
Answers
The problem could be that the image you are using is a Linux distribution (Debian) and the driver you are copying to the container it appears to be the chrome driver for Windows (
chromedriver.exe
) you need to download the chrome driver for Linux (linux64)Also make sure your java program points to the correct path for your binary inside your container. As you showed in your code, its currently pointing to a path in inside your windows machine.
I have exactly same problem. While I"m automation coding and suddenly I couldnt debug my code.I couldnt any chrome driver matched browser version.When I download the https://googlechromelabs.github.io/chrome-for-testing/ , Didnt change anything. I dont know how to solve it I’ve been searching for hours I tried many things downgrade chrome version but it couldnt…Im stuck and angry enter image description here