0

I have a question on how to start using Selenium WebDriver with Java.

Here is my code:

package newpackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class MyClass 
{
    public static void main (String[] args)
    {
        WebDriver driver = new ChromeDriver();
        driver.get("http://google.com");
    }
}

I then get the following error:

Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: C:\Users\MrJPG\eclipse-workspace\Project IG Bot\bin
Caused by: java.lang.module.InvalidModuleDescriptorException: Package IGBotPackage not found in module

Does anyone know the solution to this? I have tested adding the external jars from Selenium in both the Modulepath and Classpath. However, both seem to have the same result and error.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
jrdnangin
  • 1
  • 2
  • Does this answer your question? [InvalidModuleDescriptorException when running my first java app](https://stackoverflow.com/questions/51133398/invalidmoduledescriptorexception-when-running-my-first-java-app) – Alexey R. Mar 25 '20 at 10:49
  • If you have a module-info.java in your project, but don't want to use the Java module system, delete the module-info.java. – Mark Rotteveel Mar 25 '20 at 16:14

2 Answers2

1

you need add this

System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://google.com");

chromedriver.exe is your chromedriver.exe path //download chromedriver.exe

maybe

System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");

Need to be the same as your chrome version if your chrome is '80.0.3987.106'

need at least these are the same '80.0.3987'

Hope that helps you

Community
  • 1
  • 1
Ruyut
  • 151
  • 11
  • I just tried it, same error. I also checked the chrome driver and my chrome browser and it is the same. Where should I download the chromedriver.exe file to? I have it on my desktop – jrdnangin Mar 25 '20 at 03:25
  • You need to copy the path,and modify"C:\\chromedriver.exe",Change to your path – Ruyut Mar 25 '20 at 03:26
  • If you don't know, put it in 'C: \', try it – Ruyut Mar 25 '20 at 03:27
  • So I downloaded the chromedriver from the link you sent. It is a zip file, should I extract it and put it in C: or should I leave it in the zip? – jrdnangin Mar 25 '20 at 03:29
  • extract it, get 'chromedriver.exe' – Ruyut Mar 25 '20 at 03:30
  • Put chromedriver.exe in the 'C:\' root directory – Ruyut Mar 25 '20 at 03:32
  • Where is root directory? I put it in Program Files (x86) – jrdnangin Mar 25 '20 at 03:53
  • You can put it anywhere, but you have to copy your path, modify'System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");' – Ruyut Mar 25 '20 at 03:57
  • If you put it in the project folder,you can Use this line 'System.setProperty("webdriver.chrome.driver", "chromedriver.exe");' – Ruyut Mar 25 '20 at 03:59
  • What would the System.setProperty line look like if I leave it in my desktop? – jrdnangin Mar 25 '20 at 04:02
  • System.setProperty( "webdriver.chrome.driver","C:\\Users\\userName\\Desktop\\chromedriver.exe");//you need change userName to your computer user name – Ruyut Mar 25 '20 at 04:23
  • I am now getting this error: Error occurred during initialization of boot layer java.lang.module.FindException: Module ProjectIGBot not found – jrdnangin Mar 25 '20 at 05:12
  • This is what my code looks like right now: package newpackage; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class MyClass { public static void main (String[] args) { System.setProperty( "webdriver.chrome.driver","C:\\Users\\MrJPG\\Desktop\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://google.com"); } } – jrdnangin Mar 25 '20 at 05:13
  • Put on C:\\ Have you succeeded? – Ruyut Mar 25 '20 at 05:18
  • No i have not. I have a red underline under both the import statements, WebDriver, and ChromeDriver – jrdnangin Mar 26 '20 at 04:07
0

Please use Which ChromeDriver version is compatible with which Chrome Browser version? to download right version of chromedriver exe.

Place above exe in any(e.g. D:\) path and use below code: System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://google.com");

  • I tried this but it did not work. I have a red underline under both the import statements, WebDriver, and ChromeDriver. – jrdnangin Mar 26 '20 at 04:07
  • You have redline means you have not added selenium jar in project. Please add it in project or add maven dependency – yogesh karkhele Mar 29 '20 at 09:45