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();
它显示非法状态异常。
你的代码几乎完美但有问题。当你通过Key-Value
提到任何System.setProperty
对时,这些值是String
,不应包含任何空格。所以你需要更新这一行:
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Common Files\\chromedriver.exe" );
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