线程“main”中出现异常 java.lang.IllegalStateException:在 Ubuntu 上运行 Selenium Test 时驱动程序可执行文件不存在

2023-12-06

我在 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的系统同时指定绝对路径Gecko驱动程序你必须修剪延伸部分,即.exe部分如下:

System.setProperty("webdriver.gecko.driver", "/root/Desktop/jarselenium/geckodriver");

Update

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

  1. Gecko驱动程序存在于指定位置。
  2. Gecko驱动程序具有非root用户的可执行权限。 (chmod 777)
  3. 执行你的@Test作为非 root 用户。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

线程“main”中出现异常 java.lang.IllegalStateException:在 Ubuntu 上运行 Selenium Test 时驱动程序可执行文件不存在 的相关文章

随机推荐