2017-08-05 91 views
0

在發佈並給出解決方案之前,我已經厭倦了所有的事情,但仍然得到了相同的錯誤FireFox,Chrome & Internet Explorer。線程「main」中的異常java.lang.IllegalStateException:驅動程序可執行文件的路徑必須由webdriver.gecko.driver系統設置

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxDriver; 


public class Search { 

public static void main(String[] args) throws InterruptedException { 
    WebDriver driver = new FirefoxDriver(); 
    System.getProperty("webdriver.gecko.driver", 
      "C:\\Users\\nitin\\Downloads\\geckodriver-v0.18.0- 
    win64\\geckodriver.exe"); 
    driver.get("http://www.wikipedia.org"); 
    WebElement link; 
    link = driver.findElement(By.linkText("English")); 
    link.click(); 
    Thread.sleep(5000); 
    WebElement searchbox; 
    searchbox = driver.findElement(By.id("searchInput")); 
    searchbox.sendKeys("Software"); 
    searchbox.submit(); 
    Thread.sleep(5000); 
    driver.quit(); 

回答

0

應該不是System.setProperty()而不是.getProperty()

System.setProperty("webdriver.gecko.driver, "C:\\Users\\...\\geckodriver.exe"); 
+0

這應該指出OP的問題。謝謝 – DebanjanB

+0

我也嘗試使用.getProperty,但錯誤仍然相同 –

0

使用壁虎驅動系統屬性驅動intialization前 所以第一線壁虎財產和下一行驅動器=新某某..

0

使用.setProperty,並宣佈它提供的路徑後的webdriver

System.setProperty("webdriver.gecko.driver", 
      "C:\\Users\\nitin\\Downloads\\geckodriver-v0.18.0-win64\\geckodriver.exe"); 
WebDriver driver = new FirefoxDriver(); 
相關問題