2013-05-18 286 views
0

我试图使用webdriver启动Chrome浏览器(版本26.0)。 我收到以下错误消息。启动Chrome浏览器

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. 
    at com.google.common.base.Preconditions.checkState(Preconditions.java:176) 
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105) 
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:69) 
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107) 
    at googleSearch.main(googleSearch.java:13) 

码我用:

driver = new ChromeDriver(); 
driver.navigate().to("http://www.google.com/"); 

我使用的是Mac 10.8.2。

+0

你确定你有'''-Dwebdriver.chrome。driver ='/ path/to/driver''''设置是否正确? – luksch

+0

错误消息告诉您_webdriver.chrome.driver系统属性_有问题,然后建议_有关更多信息,请参阅http://code.google.com/p/selenium/wiki/ChromeDriver_。你看过那个,你觉得有用吗? –

回答

5

对于这个工作,你需要:

  1. 安装Chrome
  2. 安装Chrome网上应用驱动
  3. 确保您Chrome网络驱动程序在你的路径,例如在Windows上的东西指向chromedriver2_win32_0.8。您可以通过以下任一方式将其放入路径中:(a)修改您的Windows路径环境变量,或; (b)将下列到Java命令行选项:
    -Dwebdriver.chrome.driver='/path/to/driver'

在使用硒网格 -Dwebdriver.chrome.driver='/path/to/driver' 的情况下具有在创建命令行的节点被添加。

+1

谢谢你。我尝试了所有上述,但我仍然得到以下错误:线程“主”java.lang.IllegalStateException异常:驱动程序可执行文件不存在:/用户/ ... /应用/ chromedriver我使用的代码是:公共类的GoogleSearch { \t静态的webdriver驱动器; \t公共静态无效的主要(字串[] args){ \t \t System.setProperty( “webdriver.chrome.driver”,” /Users/.../Applications/chromedriver“); \t // webdriver的驱动=新FirefoxDriver(); \t webdriver的驱动=新ChromeDriver(); \t driver.nav IGATE()到( “http://www.google.com/”); –

+0

在/Users/.../Applications/chromedriver目录中是否有可执行文件? – Danger

+1

是的...有一个可执行文件chromedriver –

0

要使用chrome与selenium-webdriver一起使用,您不仅需要安装可用的Chrome浏览器,还需要安装chromedriver可执行文件。请注意,这些是需要指定的两个不同的可执行文件。

+0

谢谢。我确实在系统上安装了chrome浏览器和chrome驱动程序,并使用系统属性方法设置相同的路径。但仍然不工作:( –

0

更改文件的权限,然后再次运行您的代码。 打开命令提示符,然后导航到您的Chrome exe文件存在的目录,写

搭配chmod 777名

希望这将解决您的问题。

+0

它没有工作。 – alchemist

+0

仍然是同样的错误还是别的? –

+0

还是一样的错误。 – alchemist

1

1)在使用硒而不GRID的情况下:

System.setProperty("webdriver.chrome.driver","/absolute/path/to/chromedriver"); 
driver = new ChromeDriver(); 

做这项工作。

2)在使用硒与GRID的情况下:

System.setProperty("webdriver.chrome.driver","/absolute/path/to/chromedriver"); 
driver = new ChromeDriver(); 

而且从命令行,同时为铬浏览器一个需要通过一个节点

-Dwebdriver.chrome.driver='/absolute/path/to/chromedriver'

上面除了这个,我得到了这个libnss3.so没有找到错误,我通过在/ usr/lib/x86_64-linux-gnu /文件夹中创建libnss3.so的符号链接来解决这个错误。 O/usr/lib目录/

ln -s /usr/lib/x86_64-linux-gnu/libnss3.so /usr/lib/libnss3.so

PS:另外,还要确保您使用的是64位或Chrome驱动程序的32位版本,按您的系统。

相关问题