无法在Selenium中打开Chrome浏览器

时间:2017-12-19 08:42:49

标签: java selenium selenium-webdriver automation automated-tests

无法在Selenium中打开Chrome浏览器。

以下是代码:

package toolsqa;

import org.openqa.selenium.WebDriver;     
import org.openqa.selenium.chrome.ChromeDriver;

public class TestChrome {

    public static void main(String[] args) {     
        System.setProperty("webdriver.chrome.driver","C:\\Users\\MR049860\\Documents\\Selenium\\chromedriver_win32\\chromedriver.exe");    
        WebDriver driver=new ChromeDriver();    
        driver.get("http://www.facebook.com");     
        driver.manage().window().maximize();     
    }

}

我收到以下例外:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at toolsqa.TestChrome.main(TestChrome.java:14)

1 个答案:

答案 0 :(得分:0)

错误说明了一切:

{
    "field1": "dlrow olleh"
}

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V 中提及 Key Value 时,您必须逃避斜杠System.setProperty()。因此,您需要更改行:

(\\)

致:

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