2013-05-22 28 views
14

我試圖將Chrome設爲我的瀏覽器與webdriver的測試並正確設置chromedriver.exe文件,但我仍然得到以下錯誤:如何設置谷歌瀏覽器中的webdriver

org.openqa.selenium.WebDriverException: 
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. 
The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list 

我已經檢查過驅動程序的路徑,但仍然收到相同的錯誤。
我不知道我犯了什麼錯誤。

這裏是我的代碼:

File file = new File("C:\\chromedriver.exe"); 
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath()); 
Capability= DesiredCapabilities.chrome(); 
Capability.setBrowserName("chrome"); 
Capability.setPlatform(Platform.LINUX); 

browser=new RemoteWebDriver(new URL(nodeURL),Capability); 
browser.get(webUrl); 

請幫助我!

+0

很抱歉,如果這是要求明顯,但:你有_chromedriver.exe_在C:\驅動器? –

+0

是的,我有這個文件具有相同的名稱! – Aditya

+0

你似乎混合了'ChromeDriver'和'RemoteWebDriver'。你能描述你想要達到的目標嗎? –

回答

2

我從開始就使用它,它始終工作。 =)

System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe"); 
WebDriver driver = new ChromeDriver(); 
driver.get("http://www.google.com"); 
9

阿迪亞,

,正如你在上次您試圖訪問,以便根據您應該讓您的鍍鉻驅動程序在系統本身的一些其他系統的鍍鉻評論說。例如:如果您試圖從Windows訪問Linux chrome,那麼您需要將您的chrome驅動程序放在linux的某個位置,並授予777權限,並在Windows系統中使用以下代碼。

System.setProperty("webdriver.chrome.driver", "\\var\\www\\Jar\\chromedriver"); 
Capability= DesiredCapabilities.chrome(); Capability.setPlatform(org.openqa.selenium.Platform.ANY); 
browser=new RemoteWebDriver(new URL(nodeURL),Capability); 

這是我係統的工作代碼。

3

對於Mac - 鉻瀏覽器

public class MultipleBrowser { 

    public WebDriver driver= null; 
    String browser="mozilla"; 
    String url="https://www.omnicard.com"; 

    @BeforeMethod 
    public void LaunchBrowser() { 

     if(browser.equalsIgnoreCase("mozilla")) 
      driver= new FirefoxDriver(); 
     else if(browser.equalsIgnoreCase("safari")) 
      driver= new SafariDriver(); 
     else if(browser.equalsIgnoreCase("chrome")) 
      System.setProperty("webdriver.chrome.driver","/Users/mhossain/Desktop/chromedriver"); 
      driver= new ChromeDriver(); 
      driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); 
      driver.navigate().to(url); 
      //driver.manage().deleteAllCookies(); 

    } 
0
public void setUp() throws Exception { 

System.setProperty("webdriver.chrome.driver","Absolute path of Chrome driver"); 

driver =new ChromeDriver(); 
baseUrl = "URL/"; 

    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
    } 
+0

請提供解釋並避免代碼只回答。歡迎來到SO! –

0

這是給非法異常。

我與代碼的解決方法:

public void dofirst(){ 
    System.setProperty("webdriver.chrome.driver","D:\\Softwares\\selenium\\chromedriver_win32\\chromedriver.exe"); 
    WebDriver driver = new ChromeDriver(); 
    driver.get("http://www.facebook.com"); 
}