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.com/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