Home > Software engineering >  Exception in thread "main" java.lang.Error: Unresolved compilation problems: Syntax error
Exception in thread "main" java.lang.Error: Unresolved compilation problems: Syntax error

Time:02-12

Code trials:

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

}

Errors:

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)

So how to fix this code?

CodePudding user response:

Just like the key webdriver.chrome.driver is enclosed within double quotes, the value also needs to be enclosed within double quotes properly.

Effectively your line of code will be:

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