线程“main”中的exceptionjava.lang.IllegalStateException:在Ubuntu上运行Selenium 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的绝对路径时,您必须修剪扩展部分,即.exe
部分,如下所示:
System.setProperty("webdriver.gecko.driver", "/root/Desktop/jarselenium/geckodriver");
更新
由于您仍然看到错误,请确保:
- GeckoDriver存在于指定位置。
- GeckoDriver拥有非root用户的可执行权限。 (chmod 777)
- 以非root用户身份执行
@Test
。