我正试图在seleniumwebdriver中启动一个chromedriver,即使我给它正确的路径显示错误

问题描述 投票:0回答:2
public class sampledr {

public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    //Thread.sleep(3000);
    System.setProperty(" webdriver.chrome.driver","C:\\Program Files (x86)\\Common Files\\chromedriver.exe" );
    WebDriver d= new ChromeDriver();

它显示非法状态异常。

selenium-webdriver selenium-chromedriver
2个回答
0
投票

你的代码几乎完美但有问题。当你通过Key-Value提到任何System.setProperty对时,这些值是String,不应包含任何空格。所以你需要更新这一行:

System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Common Files\\chromedriver.exe" );

0
投票
public class sampledr {
public WebDriver driver;  //it creates the driver object 
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Common Files\\chromedriver.exe" ); //set driver path
   wd = new ChromeDriver(); //Call driver
driver.get("https://www.google.com");  //open site
© www.soinside.com 2019 - 2024. All rights reserved.