简体   繁体   中英

How do I setup Selenium WebDriver with Java?

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.

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM