I am writing a class with the following code in a maven3.6.1 project. I am using JDK 1.8.201 and declared in maven plugins section to use JDK 1.8 for source and target.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class MySeleniumTest {
WebDriverManager.chromedriver().setup();//Syntax error on token ".", { expected
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");//Syntax error, insert "}" to complete Class
driver.quit();
}
I am getting the syntax errors as shown in the comments in the same line as the code, as shown above. Even after running the maven clean and update project multiple times in Eclipse, these errors won't go away. I could not figure out why these errors are coming.
You have to put your code inside a method and you can not run directly from class scope
so modify your as like below it will run
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class MySeleniumTest {
public static void main(String[] args) {
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
driver.quit();
}
}
Also please check here for sample code