0

I am trying to replace my local geckodriver.exe with WebDriverManager, but when i invoke

WebDriverManager.firefoxdriver().setup();

i get the following error

4391 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://api.github.com/repos/mozilla/geckodriver/releases to seek geckodriver
4704 [main] WARN io.github.bonigarcia.wdm.WebDriverManager - There was an error managing geckodriver (latest version) (Type com.google.gson.internal.LinkedTreeMap not present) ... trying again using latest driver stored in cache
4704 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://api.github.com/repos/mozilla/geckodriver/releases to seek geckodriver
4876 [main] ERROR io.github.bonigarcia.wdm.WebDriverManager - There was an error managing geckodriver (latest version) (Type com.google.gson.internal.LinkedTreeMap not present)
java.lang.TypeNotPresentException: Type com.google.gson.internal.LinkedTreeMap not present
    at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
    at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
    ...
    at io.github.bonigarcia.wdm.WebDriverManager.fallback(WebDriverManager.java:825)
    at io.github.bonigarcia.wdm.WebDriverManager.handleException(WebDriverManager.java:802)
    at io.github.bonigarcia.wdm.WebDriverManager.manage(WebDriverManager.java:599)
    at io.github.bonigarcia.wdm.WebDriverManager.setup(WebDriverManager.java:287)

I am using the latest 5.0.3 WebDriverManager from maven

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.0.3</version>
</dependency>
Alex Bi
  • 3
  • 1

2 Answers2

0

Change the WebDriverManager scope to test in pom.xml as follows:

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.0.3</version>
    <scope>test</scope>
</dependency>

or change the scope to compile in pom.xml as follows:

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.0.3</version>
    <scope>compile</scope>
</dependency>

Additionally, you may need to add the slf4j dependency as follows:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.25</version>
</dependency>

As per Driver Management - Feature:

Although not mandatory, it is highly recommended to use a logger library to trace your application and tests. In the case of WebDriverManager, you will see the relevant steps of the driver management following its traces. See for example the following tutorial to use SLF4J and Logback. Also, you can see an example of a WebDriverManager test using logging here (this example uses this configuration file).


Reference

You can find a couple of relevant detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • i don't have geckodriver() in my WebDriverManager java: cannot find symbol symbol: method geckodriver() location: class io.github.bonigarcia.wdm.WebDriverManager – Alex Bi Feb 16 '22 at 19:38
  • @AlexBi Checkout the updated answer and let me know the status. – undetected Selenium Feb 16 '22 at 20:00
  • this is the source code of WebDriverManager [https://github.com/bonigarcia/webdrivermanager/blob/master/src/main/java/io/github/bonigarcia/wdm/WebDriverManager.java](https://github.com/bonigarcia/webdrivermanager/blob/master/src/main/java/io/github/bonigarcia/wdm/WebDriverManager.java) i just don't see `geckodriver()` in there – Alex Bi Feb 16 '22 at 20:44
  • What do you mean? Where do you see _`geckodriver()`_ now within this answer? – undetected Selenium Feb 16 '22 at 20:46
  • sorry, i did what you post above and i still getting the same error as the question, was assuming from the previous answer – Alex Bi Feb 16 '22 at 20:50
0

TypeNotPresentException is thrown when an application tries to access a type using a string representing the type's name, but no definition for the type with the specified name can be found.

It's pretty similar to ClassNotFoundException, but not checked during compilation.

But the root cause is:

com.google.gson.internal.LinkedTreeMap not present in the project classpath.

Try to add gson dependency to the project.

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.9.0</version>
</dependency>

Max Daroshchanka
  • 2,698
  • 2
  • 10
  • 14