2017-07-17 24 views
-1

下面的代碼使使用Selenium的瀏覽器自動化。錯誤:他必須通過webdriver.ie.driver系統屬性設置驅動程序可執行文件的路徑

public static void main(String[] args) throws InterruptedException { 
    System.setProperty("webdriver.chrome.driver", "C:\\Users\\trainee\\Downloads\\chromedriver_win32\\chromedriver.exe"); 
    WebDriver driver=new ChromeDriver(); 

    driver.get("https:\\www.google.com"); 
    //driver.manage().window().maximize(); 
    String str=driver.getCurrentUrl(); 
    System.out.println(str); 
    String abc=driver.getTitle(); 
    System.out.println(abc); 

    driver.manage().timeouts().implicitlyWait(30, TimeUnit.MINUTES); 

    driver.findElement(By.id("lst-ib")).click(); 
    driver.findElement(By.id("lst-ib")).sendKeys("Gmail"); 
    driver.findElement(By.id("lst-ib")).submit(); 
} 

當我執行的代碼,我得到這個錯誤:

java.illegalstateexception: The path to the driver executable must be set by the webdriver.ie.driver system property".

我給了正確的路徑,其中在系統中安裝的鍍鉻驅動的代碼,儘管我面對這問題。請幫我解決一下這個。

+1

你還可以添加錯誤跟蹤? –

+1

你使用鉻瀏覽器或即瀏覽器,因爲你問它是ie瀏覽器,但在代碼中它是鉻? – Murthi

回答

1

將驅動程序放置在某個位置,如C:\ Selenium \ iexploredriver.exe。您可以從here下載IE驅動程序。

然後

File file = new File("C:/Selenium/iexploredriver.exe"); 
System.setProperty("webdriver.ie.driver", file.getAbsolutePath()); 
WebDriver driver = new InternetExplorerDriver(); 

希望它會幫助你。

0

處理此問題的最簡單方法是將路徑添加到您的webdriver可執行文件到PATH環境變量中。

這樣,您不必擔心代碼中驅動程序可執行文件的位置,而是來自環境配置。

如果使用chrome和firefox,可以在windows,mac和linux上移植,您可以在上述任何操作系統上運行selenium代碼,而無需指定驅動程序的路徑,但可以正確配置您將運行的環境測試(將路徑放到PATH env var中)。

在這條線----> 「System.setProperty
1

(」 webdriver.chrome.driver」, 「C:\ Users \用戶受訓者\下載\ chromedriver_win32 \ chromedriver.exe」); 移除的額外文件(.exe )從鉻駕駛員的路徑

嘗試與刪除此行.exe擴展

System.setProperty( 「webdriver.chrome.driver」, 「C:\ Users \用戶受訓者\下載\ chromedriver_win32 \ chromedriver」);

相關問題