本文介绍了线程“main"中的异常java.lang.IllegalStateException:在 Ubuntu 上运行 Selenium 测试时驱动程序可执行文件不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Eclipse 中尝试过这段代码:
I have tried this code in 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 的位置?
How can i set geckodriver location in ubuntu?
推荐答案
当您使用 Linux based System 时,同时指定 GeckoDriver 的绝对路径,您必须修剪扩展部分即.exe
部分如下:
As you are using Linux based System while specifying the absolute path of the GeckoDriver you have to trim the extension part i.e. .exe
part as follows :
System.setProperty("webdriver.gecko.driver", "/root/Desktop/jarselenium/geckodriver");
更新
当您仍然看到错误时,请确保:
Update
As you are still seeing the error ensure that :
- GeckoDriver 存在于指定位置.
- GeckoDriver 对非 root 用户具有可执行权限.(chmod 777)
- 以非 root 用户身份执行您的
@Test
.
- GeckoDriver is present in the specified location.
- GeckoDriver is having executable permission for non-root users. (chmod 777)
- Execute your
@Test
as a non-root user.
这篇关于线程“main"中的异常java.lang.IllegalStateException:在 Ubuntu 上运行 Selenium 测试时驱动程序可执行文件不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!