Java中的org.openqa.selenium.WebDriverException

时间:2018-10-29 12:36:45

标签: selenium web exception driver

我是Automation的新手,正在尝试以手动测试员的身份学习Automation。我正在尝试执行一个简单的Java代码,以使用Selenium Webdrivers打开Chrome浏览器,并获得以下异常。尝试了所有可能的方法来解决相同问题,但仍然没有任何效果。任何帮助都会真正有帮助。谢谢。

Starting ChromeDriver 2.28.455520 (cc17746adff54984afff480136733114c6b3704b) on port 3527
Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 4.67 seconds
Build info: version: '2.51.0', revision: '1af067d', time: '2016-02-05 19:11:55'
System info: host: 'BTP196816', ip: '10.241.51.20', os.name: 'Windows 8.1', os.arch: 'x86', os.version: '6.3', java.version: '1.7.0_99'
Driver info: org.openqa.selenium.chrome.ChromeDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:170)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:159)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)
    at OpenAdf.LaunchAdf.main(LaunchAdf.java:11)

2 个答案:

答案 0 :(得分:0)

尝试使用:

        System.setProperty("webdriver.chrome.driver", "C:\\SeleniumDrivers\\chromedriver_win32\\chromedriver.exe");
        DesiredCapabilities capability = new DesiredCapabilities();
        capability.setCapability("binary", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
        WebDriver driver = new ChromeDriver(capability);

您也可以尝试

capability.setCapability("chrome.binary", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");

希望有帮助。

答案 1 :(得分:0)

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

需要设置chrome驱动程序路径,并且chrome驱动程序路径必须位于您在代码中指定的位置。