Trying to use FireFox driver for doing some manipulations with webbrowser, but when i dockered my app i faced with error that i posted down.
Using Selenium, Firefox-driver and maven:3.6.1-jdk-8-alpine image with fierfox-esr and xvfb on it
Some piece of program:
@Scheduled(fixedRate = 20000)
public void main() throws InterruptedException, IOException {
System.setProperty("webdriver.gecko.driver", "Gecko/geckodriver");
QueueEntity queue = QueueDAO.next();
if (queue != null) {
WebDriver driver = new FirefoxDriver();
Last line causes an error:
1637168554124 geckodriver INFO Listening on 127.0.0.1:24425
2021-11-17T17:02:34.134011600Z 1637168554133 mozrunner::runner INFO Running command: "/usr/bin/firefox" "--marionette" "-no-remote" "-profile" "/tmp/rust_mozprofileUkF2hH"
2021-11-17T17:02:36.256633700Z 1637168556256 Marionette INFO Listening on port 45371
2021-11-17T17:02:36.347875300Z 1637168556347 Marionette WARN TLS certificate errors will be ignored for this session
2021-11-17T17:02:36.413224000Z 2021-11-17 17:02:36.412 INFO 54 --- [ null to remote] o.o.selenium.remote.ProtocolHandshake : Detected dialect: W3C
2021-11-17T17:02:36.414915900Z 2021-11-17 17:02:36.414 ERROR 54 --- [ scheduling-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task
2021-11-17T17:02:36.415000400Z
2021-11-17T17:02:36.415009800Z java.lang.NoClassDefFoundError: org/openqa/selenium/remote/RemoteWebElement
2021-11-17T17:02:36.415013100Z at org.openqa.selenium.remote.internal.JsonToWebElementConverter.apply(JsonToWebElementConverter.java:63) ~[selenium-remote-driver-3.141.59.jar:na]
2021-11-17T17:02:36.415016400Z at com.google.common.collect.Maps$9.transformEntry(Maps.java:1955) ~[guava-25.0-jre.jar:na]
2021-11-17T17:02:36.415019300Z at com.google.common.collect.Maps$12.getValue(Maps.java:1996) ~[guava-25.0-jre.jar:na]
2021-11-17T17:02:36.415022100Z at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:222) ~[selenium-remote-driver-3.141.59.jar:na]
2021-11-17T17:02:36.415025000Z at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131) ~[selenium-remote-driver-3.141.59.jar:na]
2021-11-17T17:02:36.415028100Z at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:147) ~[selenium-firefox-driver-3.141.59.jar:na]
2021-11-17T17:02:36.415030900Z at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125) ~[selenium-firefox-driver-3.141.59.jar:na]
2021-11-17T17:02:36.415033800Z at staff.parser.scheduler.loopedMain.main(loopedMain.java:29) ~[classes/:na]
2021-11-17T17:02:36.415036600Z at sun.reflect.GeneratedMethodAccessor41.invoke(Unknown Source) ~[na:na]
2021-11-17T17:02:36.415048800Z at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]
2021-11-17T17:02:36.415052300Z at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]
2021-11-17T17:02:36.415055500Z at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.3.12.jar:5.3.12]
2021-11-17T17:02:36.415060700Z at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.3.12.jar:5.3.12]
2021-11-17T17:02:36.415065500Z at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_212]
2021-11-17T17:02:36.415070500Z at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_212]
2021-11-17T17:02:36.415074200Z at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_212]
2021-11-17T17:02:36.415077800Z at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_212]
2021-11-17T17:02:36.415080700Z at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_212]
2021-11-17T17:02:36.415083500Z at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_212]
2021-11-17T17:02:36.415086300Z at java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]
2021-11-17T17:02:36.415089000Z
Using maven
Dependencies from pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.6.0.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.26</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-common</artifactId>
<version>2.0b1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
All that is running in docker (alpine)
DockerFile:
FROM maven:3.6.1-jdk-8-alpine
COPY ./src /app/src
COPY ./Gecko /app/Gecko
COPY pom.xml /app
WORKDIR /app
EXPOSE 3000
RUN mvn package
Run apk update
Run apk add xvfb
Run apk add firefox-esr
Run Xvfb :9 &
CMD ["mvn", "spring-boot:run"]
Also specifying Display=:9 as an environment variable
Will be glad for any help^_^
CodePudding user response:
Though you mentioned about adding the following dependencies:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>4.0.0</version>
</dependency>
But as per the error stack trace your program is looking for:
selenium-remote-driver-3.141.59.jar:na
selenium-remote-driver-3.141.59.jar:na
selenium-firefox-driver-3.141.59.jar:na
Hence, the class definations aren't found and you see the error java.lang.NoClassDefFoundError
Checkout your dockered app configuration to resolve the conflict between Selenium v3.141.59 and v4.0.0