线程 "main" java.lang.IllegalStateException 中的异常:运行 Ubuntu 上的 Selenium 测试时驱动程序可执行文件不存在
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist while running Selenium Test on Ubuntu
我在 eclipse 中试过这段代码:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class auto {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "/root/Desktop/jarselenium/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.easybooking.lk/login");
//driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
}
}
执行时出现此错误:
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: /root/Desktop/jarselenium/geckodriver.exe
如何在 ubuntu 中设置 geckodriver 位置?
由于您正在使用基于 Linux 的系统,同时指定 GeckoDriver 的绝对路径,您必须 trim 扩展部分即 .exe
部分如下:
System.setProperty("webdriver.gecko.driver", "/root/Desktop/jarselenium/geckodriver");
更新
因为您仍然看到错误,请确保:
- GeckoDriver 存在于指定位置。
- GeckoDriver 具有非根用户的可执行权限。 (chmod 777)
- 以非 root 用户身份执行
@Test
。
我在 eclipse 中试过这段代码:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class auto {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "/root/Desktop/jarselenium/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.easybooking.lk/login");
//driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
}
}
执行时出现此错误:
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: /root/Desktop/jarselenium/geckodriver.exe
如何在 ubuntu 中设置 geckodriver 位置?
由于您正在使用基于 Linux 的系统,同时指定 GeckoDriver 的绝对路径,您必须 trim 扩展部分即 .exe
部分如下:
System.setProperty("webdriver.gecko.driver", "/root/Desktop/jarselenium/geckodriver");
更新
因为您仍然看到错误,请确保:
- GeckoDriver 存在于指定位置。
- GeckoDriver 具有非根用户的可执行权限。 (chmod 777)
- 以非 root 用户身份执行
@Test
。