【问题标题】:Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist while running Selenium Test on Ubuntu线程“主”java.lang.IllegalStateException 中的异常:在 Ubuntu 上运行 Selenium 测试时驱动程序可执行文件不存在
【发布时间】:2018-09-29 22:33:11
【问题描述】:

我在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 位置?

【问题讨论】:

    标签: java selenium ubuntu selenium-webdriver geckodriver


    【解决方案1】:

    当您使用 Linux based System 并指定 GeckoDriver 的绝对路径时,您必须修剪扩展部分,即.exe 部分,如下所示:

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

    更新

    当您仍然看到错误时,请确保:

    1. GeckoDriver 存在于指定位置。
    2. GeckoDriver 对非 root 用户具有可执行权限。 (chmod 777)
    3. 以非 root 用户身份执行 @Test。

    【讨论】:

    • 线程“main”java.lang.IllegalStateException中的相同错误异常:驱动程序可执行文件不存在:/root/Desktop/jarselenium/geckodrive。
    • @sanjan 查看我的答案更新并让我知道状态。不要错过geckodriver 末尾的e。
    • thz 它的工作,但 //driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);如果启用此行 TimeUnit 这是错误
    • @sanjan 从您的@Tests 中完全删除implicitlyWait,因为它不再有效,从长远来看,您只需要使用 WebDriverWait
    猜你喜欢
    • 2018-06-09
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    • 2017-04-08
    • 2018-03-18
    相关资源
    最近更新 更多