I am trying to learn selenium with Java for work and I keep getting an error on my setProperty method.
package src;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebElement;
public class HelloWorld {
public static void main(String[] args){
System.out.println("Hello World");
System.setProperty(“webdriver.chrome.driver”, error--->“C:\\Users\\cchadwell\\Desktop\\chromedriver.exe”); <---error right here
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
driver.quit();
}
}
I've looked in other places an compared my code but saw no difference.
Here is the error that is produced...
Exception in thread "main" java.lang.IllegalStateException: iver executable must be set by the webdriver.chrome.driver sr more information, see https://github.com/SeleniumHQ/selenier. The latest version can be downloaded from http://chromedleapis.com/index.html
It's also pointing to some syntax errors that I am am having a hard time spotting at that line I pointed out in the code example above.
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token "Invalid Character", delete this
token
Syntax error on tokens, delete these tokens
chromedriver cannot be resolved to a variable
Syntax error on token "Invalid Character", delete this
token
Help would be appreciated please!
CodePudding user response:
Although you've got the resolution for your problem, I'd suggest you to use the WebDriverManager instead of this hardcoded browser drivers, and you won't have to worry about setting the path etc.
Add this dependency to your pom.xml file if you're working on a Maven Project, and if you're using a regular Java project, then just download the JAR file for WebDriverManager from Maven Repository and add it to your project.
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.4.3</version>
</dependency>
And then use this piece of code in your test file so that you do not need to worry about downloading browser driver files and setting path etc.
WebDriver driver;
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.get("https://www.google.com/");