Exception in thread "main" java.lang.Error: Unresolved compilation problems: Syntax error on token "Invalid Character" executing Selenium Java program

Exception in thread "main" java.lang.Error: Unresolved compilation problems: Syntax error on token "Invalid Character" executing Selenium Java program

代码试验:

package split;

public class locators {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.setProperty(“webdriver.chrome.driver”, “C/Users/sai/Documents/chromedriver.exe);
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com");
        driver.getTitle();
    }

}

错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    Syntax error on token "Invalid Character", delete this token
    webdriver cannot be resolved to a variable
    Syntax error on tokens, delete these tokens
    Users cannot be resolved to a variable
    sai cannot be resolved to a variable
    Documents cannot be resolved to a variable
    chromedriver cannot be resolved to a variable
    WebDriver cannot be resolved to a type
    ChromeDriver cannot be resolved to a type

    at split.locators.main(locators.java:7)

那么如何修复此代码?

就像key webdriver.chrome.driver双引号括起来一样, 也需要用双引号括起来。

实际上你的代码行将是:

System.setProperty("webdriver.chrome.driver", "C:\Users\sai\Documents\chromedriver.exe");