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

时间:2018-01-02 06:21:05

标签: selenium-webdriver selenium-chromedriver

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();

它显示非法国家例外。

2 个答案:

答案 0 :(得分:0)

您的代码几乎完美但有问题。当您通过 diff-files 提及任何 Key-Value 对时,这些值为 System.setProperty ,不应该包含任何空格。因此,您需要将该行更新为:

String

答案 1 :(得分: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