2016-08-05 44 views
0

我有以下错误enter image description here硒在Java日食的Linux

,这里是我的代码

import org.openqa.*; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 
public class io { 

/** 
* @param args 
*/ 
public static void main(String[] args) { 
    WebDriver driver=new ChromeDriver(); 

} 

} 

我提到这个错误只出现时,做“新ChromeDriver()”。如果我让没有它不这样做,我不知道我需要做什么来解决它。请帮助。

编辑:当我执行程序时,我下载铬驱动程序它工作正常,但当我调试它暂停。为什么会发生这种情况?

+0

您必须在创建chrome驱动程序的实例之前设置System属性。在初始化chromedriver之前,请在您的机器中下载chromedriver并在代码中添加以下代码。 'System.setProperty(“webdriver.chrome.driver”,“<路径到chromedriver>”);'。 – Harish

+0

对于上述错误,看起来像您没有将'selenium-server-standalone-3.0.0-beta'添加到您的项目中。你可以通过将Selenium jar添加到你的项目库中来实现。右键单击您的项目 - > Buildpath - > Configure buildpath - > Libraries。添加你的selenium-server-standalone-3.0.0-beta.jar并点击'Apply'然后'OK'按钮。 – Harish

+0

但我做到了。看看我的例子上面,你会看到这个库在参考库 – User124235

回答

0

您必须在创建chrome驱动程序的实例之前设置System属性。在初始化chromedriver之前,请在您的机器中下载chromedriver并在代码中添加以下代码。

System.setProperty("webdriver.chrome.driver","<path to chromedriver>"); 

希望它有帮助。

+0

我安装了铬驱动程序的东西,但我无法找到系统中的任何文件来给路径。请看我最后的评论,并回复我 – User124235

+0

根据你的操作系统下载chromedriver。在您的项目中创建一个drectory(称为'libs'),并将下载的chromedriver复制到该文件夹​​中。然后添加'System.setProperty(“webdriver.chrome.driver”,“./libs/chromedriver”);'。希望能帮助到你。 – Harish

0

看看我的项目https://github.com/codezombies/easytest。我的项目中的一个方法使得chrome驱动程序初始化在测试运行之前发生(实际上是在驱动程序类型选择时)。据说,我在不同的操作系统上嵌入了3种类型的chrome驱动程序,并且它在linux上也应该可以正常工作。