1

當我修改代碼與RemoteWebDriver和ChromeDriver我正在運行:異常:在驅動程序可執行文件的路徑必須由webdriver.chrome.driver系統屬性進行設置;異常:驅動程序可執行文件的路徑必須由webdriver.chrome.driver系統屬性設置;帶遙控的webdriver

代碼:

File file = new File("C:/WebDrivers/chromedriver.exe"); 
System.setProperty("webdriver.chrome.driver",file.getAbsolutePath()); 
HashMap<String, Object> chromePrefs = new HashMap<String, Object>(); 
chromePrefs.put("profile.default_content_settings.popups", 0); 
chromePrefs.put("download.default_directory", Path_FileDownload); 
ChromeOptions options = new ChromeOptions(); 
options.setExperimentalOption("prefs", chromePrefs); 
DesiredCapabilities cap = DesiredCapabilities.chrome(); 
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); 
cap.setCapability(ChromeOptions.CAPABILITY, options); 
driver = new RemoteWebDriver(new URL("http://192.168.224.160:4444/wd/hub"), cap); 
//driver = new ChromeDriver(cap); 
driver.manage().window().maximize(); 
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 

該文件存在,我運行它的計算機上。當我切換到ChromeDriver而不是遠程WebDriver工作得很好。

+0

歡迎硒地獄。看起來你的路徑不正確。您系統上的chromedriver可執行文件在哪裏? –

+0

它位於C:\ WebDrivers \ chromedriver.exe。 –

回答

0

你必須在你的路徑開始兩條斜線:
"C://WebDrivers" + "/chromedriver.exe"
應該
"C:/WebDrivers" + "/chromedriver.exe"

的Java文件路徑中使用「/」分隔的目錄和文件,同基於UNIX的系統。

+0

我必須有第二個斜線才能逃出第一個斜線。否則,Java會給出錯誤。 –

+0

不,你沒有。你必須逃避'\'而不是'/'。 –

+0

仍然收到相同的錯誤。我將文件行修改爲:「C:/WebDrivers/chromedriver.exe」,當我將其放入文件資源管理器時加載該文件。 –

0
ChromeOptions options = new ChromeOptions(); 
    options.setBinary("Chrome_Binary/chrome.exe"); 
    options.addArguments("--start-fullscreen"); 
    System.setProperty("webdriver.chrome.driver", "Drivers/Chrome/chromedriver.exe"); 
    DesiredCapabilities cap = DesiredCapabilities.chrome(); 
    cap.setCapability(ChromeOptions.CAPABILITY, options); 
0

線條

File file = new File("C:/WebDrivers/chromedriver.exe"); 
System.setProperty("webdriver.chrome.driver",file.getAbsolutePath()); 

工作,只有當你使用ChromeDriver。我將這種模式稱爲local模式,即運行測試用例的JVM也會關閉瀏覽器。

當您使用RemoteWebDriver時,您正在使用remote模式,因爲脫離測試用例的JVM與另一個JVM(Selenium節點)進行通信以分離瀏覽器。

當你與RemoteWebDriver工作,你要連接到不同的JVM中運行作爲通過集線器的節點。

對於其中的節點運行,你需要做在機器下面的這一個用例:

  • 添加C:\WebDriversPATH變量。確保通過打開新的命令提示符並運行echo %PATH%來確認它已正確添加。您應該在命令輸出中看到C:\WebDrivers(或)
  • 加入webdriver.chrome.driver作爲JVM參數啓動節點。對於例如,像這樣:
相關問題