Java Selenium Chromedriver.exe 不存在 IllegalStateException
在方法 System.setProperty 中不正確設定 chromedriver.exe 檔案路徑時,使用 Chrome 瀏覽器時會丟擲 IllegalStateException。一旦下載了此可執行檔案,就必須提取它。然後應該複製其路徑並將其作為引數新增到 System.setProperty 方法中。
語法
System.setProperty("webdriver.chrome.driver",
"C:\Users\ghs6kor\Desktop\DebomitaJava\chromedriver.exe")另外,必須記住,對於 Windows,必須在包含路徑時指定 .exe 副檔名。但 Mac 或 Ubuntu 不需要。我們還應該確保我們正在使用的 chromedriver.exe 檔案與本地 Chrome 瀏覽器版本相容。
讓我們看一個 IllegalStateException 的示例。

示例
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class PathChromeDriver{
public static void main(String[] args) {
//path of chromedriver.exe set
System.setProperty("webdriver.chrome.driver",
"C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//implicit wait
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//launch URL
driver.get("https://tutorialspoint.tw/about/about_careers.htm");
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP