2016-07-05 156 views
0

我試圖使用selenium weDriver加載chrome配置文件。配置文件加載正常,但嘗試加載URL時失敗。如果另一個chrome實例打開,Selenium chromedriver不會啓動URL

我注意到這個問題發生在有另一個chrome實例打開時,不管它是否被webDriver打開。我有硒2.53.1。

System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe"); 
ChromeOptions options = new ChromeOptions(); 
options.addArguments("user-data-dir=C:/Users/useName/AppData/Local/Google/Chrome/User Data"); 
options.addArguments("--start-maximized"); 
driver = new ChromeDriver(options); 

driver.get("www.google.com") // here is where it fails. It works fine if I close all chrome browsers before I run the test 
+0

那不是possible.But你可以調整根據您的需要圍繞[看看這個](http://stackoverflow.com/q/27630091/3122133) – Madhan

回答

3

我找到了解決此問題的解決方法。我注意到發生了這個問題,因爲如果有另一個打開的實例使用相同的配置文件,則chromedriver將無法使用相同的配置文件啓動。例如,如果chrome.exe已經使用默認配置文件打開,chromedriver.exe將無法啓動默認配置文件,因爲chrome.exe已打開並使用相同的配置文件。

要解決此問題,您需要通過複製默認配置文件來創建單獨的自動配置文件,以便chromedriver.exe和chrome.exe不共享相同的默認配置文件。

默認的Chrome個人資料是在以下位置:

C:\用戶\ yourUserName \應用程序數據\本地\谷歌\鍍鉻\用戶數據\

複製從用戶數據文件夾中的所有文件到一個新的文件夾並將其稱爲AutomationProfile

將文件複製到新文件夾後,即可將其用於腳本。

 String userProfile= "C:\\Users\\YourUserName\\AppData\\Local\\Google\\Chrome\\AutomationProfile\\"; 
     ChromeOptions options = new ChromeOptions(); 
     options.addArguments("user-data-dir="+userProfile); 
     options.addArguments("--start-maximized"); 

     driver = new ChromeDriver(options); 

確保您在測試結束使用driver.quit(),這樣你不保持chromedriver.exe打開

+0

我已經有這個問題多年了:(希望有一個官方的解決方案。 –

相關問題