java.lang.IllegalStateException:驱动程序可执行文件的路径必须由

这是我的代码:


package Basics;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;


public class invokegoogle {


    public static void main(String[] args) {

        // TODO Auto-generated method stub


    System.setProperty("Webdriver.chrome.driver", "C:\\Users\\sravani\\Desktop.exe");

    WebDriver driver=new ChromeDriver();

    driver.get("http://qaclickacademy.com");


    }


}

出现以下错误:


Exception in thread "main" java.lang.IllegalStateException: 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 http://chromedriver.storage.googleapis.com/index.html

    at com.google.common.base.Preconditions.checkState(Preconditions.java:754)

    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)

    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)

    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)

    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329)

    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)

    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:124)

    at Basics.invokegoogle.main(invokegoogle.java:12)

非常感谢您的帮助。提前致谢


尚方宝剑之说
浏览 2668回答 2
2回答

慕沐林林

假设chromedriver.exe存放在您的桌面上,则需要进行如下更改:更改:System.setProperty("Webdriver.chrome.driver", "C:\\Users\\sravani\\Desktop.exe");至:System.setProperty("webdriver.chrome.driver", "C:\\Users\\sravani\\Desktop\\chromedriver.exe");请注意,“ webdriver.chrome.driver”必须以小写字母开头。

撒科打诨

将chrome驱动程序下载到系统中后,将其解压缩(解压缩)到文件夹后,您似乎已经直接复制了文件夹路径“ Downloads / chromedriver_win32.exe”,而不是使用如下所述的完整路径打开文件夹(chromedriver_win32.exe),然后您将看到“ chromedriver.exe”为.exe文件,并改用此路径,它看起来像这样System.setProperty("webdriver.chrome.driver", C:\Downloads\chromedriver_win32\chromedriver.exe");这会起作用
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java