Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ChromeDriver不与OS X上的浏览器通信_Java_Selenium_Selenium Chromedriver - Fatal编程技术网

Java ChromeDriver不与OS X上的浏览器通信

Java ChromeDriver不与OS X上的浏览器通信,java,selenium,selenium-chromedriver,Java,Selenium,Selenium Chromedriver,我试图在OS X上用chrome运行selenium测试。它在firefox上运行良好,但chrome驱动程序似乎无法与浏览器通信 这是我的密码: import junit.framework.TestCase; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class DriverTest extends TestCase {

我试图在OS X上用chrome运行selenium测试。它在firefox上运行良好,但chrome驱动程序似乎无法与浏览器通信

这是我的密码:

import junit.framework.TestCase;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class DriverTest extends TestCase {

    public void testFirefox(){
        FirefoxDriver driver = new FirefoxDriver();
        driver.get("http://www.google.com");
        driver.close();
    }

    public void testChrome(){
        ChromeDriver driver = new ChromeDriver();
        driver.get("http://www.google.com");
        driver.close();
    }    
}
当我运行它时,firefox启动良好,但对于chrome,我会出现以下错误:

Started ChromeDriver
port=45421
version=23.0.1240.0
log=/Users/user/projects/client/hg/chromedriver.log
objc[25753]: Object 0x6e078170 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[25753]: Object 0x6e078360 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[25753]: Object 0x6e078410 of class NSConcreteData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[25753]: Object 0x6e078470 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[25753]: Object 0x6e0782c0 of class NSBundle autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 22:18:01'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.7.4', java.version: '1.6.0_35'
Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:493)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:182)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:165)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
    at DriverTest.testChrome(DriverTest.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
Caused by: org.openqa.selenium.WebDriverException: Unable to convert: {desiredCapabilities=Capabilities [{platform=ANY, browserName=chrome, chromeOptions=org.openqa.selenium.chrome.ChromeOptions@448be1c9, chrome.switches=[], version=}]}
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 22:18:01'

您需要指定一个指向Chromedriver位置的系统属性,例如:

System.setProperty("webdriver.chrome.driver", "applications/chrome/chromedriver");

其中,第二个参数应设置为保存chromedriver的路径。

尝试为chromedriver设置DesiredCapabilities.chrome

ChromeDriver driver = new ChromeDriver(DesiredCapabilities.chrome());

这应该行得通。

您有什么版本的Chrome?您是否遵循了以下步骤:安装ChromeDriver服务器?