• Selenium 3 -how to locate the chromedriver and geckodriver place?


    Maybe you met these exceptions sometimes:

    1. Chrome Driver

    The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html

    2. Firefox Driver

    The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases

    After checking the selenium source code, I had found that the rule how they located these drivers in new selenium 3 API:

    Invoke the WebDriver

    org.openqa.selenium.chrome.ChromeDriver.ChromeDriver()
    
    ChromeDriverService.createDefaultService();
    
    new Builder().usingAnyFreePort().build();
    
    org.openqa.selenium.remote.service.DriverService.Builder.build();
    
    org.openqa.selenium.chrome.ChromeDriverService.Builder.findDefaultExecutable()
    
    org.openqa.selenium.remote.service.DriverService.findExecutable(String, String, String, String)
    String defaultPath = CommandLine.find(exeName);
    
    String exePath = System.getProperty(exeProperty, defaultPath);
    
    checkState(exePath != null,
    
    "The path to the driver executable must be set by the %s system property;"
    
    + " for more information, see %s. "
    
    + "The latest version can be downloaded from %s",
    
    exeProperty, exeDocs, exeDownload);
    
     
    
     
    
    public String find(String named) {
    
    File file = new File(named);
    
    if (canExecute(file)) {
    
    return named;
    
    }
    
     
    
    if (Platform.getCurrent().is(Platform.WINDOWS)) {
    
    file = new File(named + ".exe");
    
    if (canExecute(file)) {
    
    return named + ".exe";
    
    }
    
    }
    
     
    
    addPathFromEnvironment();
    
    if (Platform.getCurrent().is(Platform.MAC)) {
    
    addMacSpecificPath();
    
    }
    
     
    
    for (String pathSegment : pathSegmentBuilder.build()) {
    
    for (String ending : ENDINGS) {
    
    file = new File(pathSegment, named + ending);
    
    if (canExecute(file)) {
    
    return file.getAbsolutePath();
    
    }
    
    }
    
    }
    
    return null;
    
    }

    1. First option is place the driver file in your current WebDriver or RemoteWebDriver instance,for example:

    If you current selenium server path is: /usr/selenium-server-version.jar ,then you must put the driver into this place

    /usr and also MUST NOT change the driver’s name .

    2. Add the driver into the PATH environment variable, in linux kernel system, you can put it into this place: /etc/paths.

    For windows system you can put it in System environment or User environment Path variable .and also MUST NOT change the driver’s name.

    3. Using programmatically java Code: System.setProperty(“”,””) here you can change the driver’s name.

    Issues: Selenium Server is developed by Java, and using System.getEnv() to find the PATH variable ,so maybe the cache issue ,cannot located it correctly. When you changed the environment Path for chromedriver you need to restart the Java virtual machine again to make the changes affected.

  • 相关阅读:
    使用WebAPI流式传输大文件(在IIS上大于2GB)
    网页扫描仪图像上传
    网页高拍仪图像上传
    C++
    Tomcat Connector三种执行模式(BIO, NIO, APR)的比較和优化
    编程精粹--编写高质量C语言代码(1):假想编译程序
    一个软件项目的总纲性的測试计划叫什么?
    Java字符串的格式化与输出
    Servlet入门(第一个Servlet的Web程序)
    求职小技巧,赢得大机会
  • 原文地址:https://www.cnblogs.com/seniortestingdev/p/5754929.html
Copyright © 2020-2023  润新知