Home > Software design >  Setting up Selenium correctly
Setting up Selenium correctly

Time:10-02

I have been trying to install Selenium for about a day now, and I can´t get it to work. First, I just downloaded the standalone jar and added it as a user library. That did work out fine, until I wanted to use org.openqa.selenium.htmlunit.HtmlUnitDriver. Apparently, this library is not included in the jar. So I downloaded the jar file for the htmlUnitDriver seperately. That did not work out at all, as I got an error in line 1 saying, that some library is "indirectly referenced from required .class files". I deinstalled the libraries again and tried it with Maven. I included dependencies for selenium and the selenium htmlUnitDriver (as it again was not included). But that still left me with the same problem. Below is my pom.xml file and the exact error message.

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.0.0-rc-1</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-htmlunit-driver</artifactId>
            <version>2.52.0</version>
        </dependency>
    </dependencies>
    <modelVersion>4.0.0</modelVersion>
    <groupId>WebsiteRequest</groupId>
    <artifactId>WebsiteRequest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>12</release>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

The java code:

package pack;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class Klasse  {

    public static void main(String[] args) {
        
        WebDriver driver = new HtmlUnitDriver();

    }
}

The error message: Error Message

I have noticed, that the error only occurs, when I initialise a WebDriver as a HtmlUnitDriver. Otherwise it is still shown, but not marked as an error: The other variant of the error message

CodePudding user response:

There was a change one year ago which removes a list of interfaces. Those interfaces are used (implemented) by HtmlUnitDriver. The change was delivered in selenium-4.0.0-alpha-7 release.

So the solution would be to use Selenium release prior to mentioned one.

Either: (this is not stable version with some features of Selenium 4)

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.0.0-alpha-6</version>
</dependency>

Or:

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>

The latter is the most stable and recent version of Selenium 3.

  • Related