我在 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 的绝对路径,因此您必须修剪扩展部分,即 .exe
部分如下:
System.setProperty("webdriver.gecko.driver", "/root/Desktop/jarselenium/geckodriver");
<小时/>
更新
由于您仍然看到错误,请确保:
- GeckoDriver 存在于指定位置。
- GeckoDriver 对非 root 用户具有可执行权限。 (chmod 777)
- 以非 root 用户身份执行
@Test
。
关于java - 线程中的异常 "main"java.lang.IllegalStateException : The driver executable does not exist while running Selenium Test on Ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49920781/