java - 线程中的异常 "main"java.lang.IllegalStateException : The driver executable does not exist while running Selenium Test on Ubuntu

标签 java selenium ubuntu selenium-webdriver geckodriver

我在 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");
<小时/>

更新

由于您仍然看到错误,请确保:

  1. GeckoDriver 存在于指定位置。
  2. GeckoDriver 对非 root 用户具有可执行权限。 (chmod 777)
  3. 以非 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/

相关文章:

java - 如何使用bundle将数据从fragment传递到activity

java - eclipse.ini 非标准选项

selenium - MacOS 运行时,在 lambda 上调用 Screenshot_as_base64 时出错

python - 问题爬取亚马逊,元素无法滚动到 View 中

bash - "watch"如何处理串联命令?

c# - Monodevelop 不会运行任何项目

java.util.AbstractList.remove 处的 java.lang.UnsupportedOperationException

java - Selenium 在 Firefox 浏览器窗口中运行一些测试时出现 "Can' t 查找配置文件目录错误

c++ - 如何在 Ubuntu 16.04 中安装 MySql Connector/C++

java - 使用 UnetSocket 在 unetstack 中创建客户端和服务器节点之间的通信