简体   繁体   English

无法在 vs 代码上运行 selenium 测试

[英]can't run selenium test on vs code

     import org.openqa.selenium.WebDriver;
     import org.openqa.selenium.chrome.ChromeDriver;

public class App {
    public static void main(String[] args) throws Exception {
        System.out.println("hi"); 
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com");
        driver.quit(); 
    }
}

I imported jar file for selenium and downloaded right webchrome drive and it give me error我为 selenium 导入了 jar 文件并下载了正确的 webchrome 驱动器,但它给了我错误

PS D:\software testing task 2>  & 'C:\Program Files\Java\jdk-17.0.1\bin\java.exe' '-XX:+ShowCodeDetailsInExceptionMessages' '@C:\Users\mohamed\AppData\Local\Temp\cp_apvu20bu2lqgd550a094p3mwf.argfile' 'App' 
zzzzzzzzzz
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from https://chromedriver.storage.googleapis.com/index.html
        at org.openqa.selenium.internal.Require$StateChecker.nonNull(Require.java:311)
        at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:135)
        at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:38)
        at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:231)
        at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:437)
        at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:127)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:48)
        at App.main(App.java:7)

Driver path should be set before browser launch as given below.驱动程序路径应在浏览器启动之前设置,如下所示。

 System.setProperty("webdriver.chrome.driver","D:\List_of_Jar\chromedriver.exe"); WebDriver wd =new ChromeDriver(); String baseUrl = "https://www.google.com"; wd.get(baseUrl);"

Getting "The path to the driver executable must be set by the webdriver.chrome.driver system property"though set correct path 获取“驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置”虽然设置正确的路径

The path to the driver executable must be set by the webdriver.chrome.driver system property ;驱动程序可执行文件的路径必须由webdriver.chrome.driver 系统属性设置; for more information:了解更多信息:

System.setProperty("<Path to>chromedriver.exe");

Absolute Path: System.setProperty("webdriver.chrome.driver","D:\List_of_Jar\chromedriver.exe");绝对路径: System.setProperty("webdriver.chrome.driver","D:\List_of_Jar\chromedriver.exe");

Relative Path:相对路径:

System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"./Driver\\chromedriver.exe");

Path to the driver must be set before webdriver object creation and check browser version and chromedriver version.必须在创建 webdriver 对象之前设置驱动程序的路径,并检查浏览器版本和 chromedriver 版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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