首页 文章

使用RemoteWebdriver获取chromedriver错误

提问于
浏览
1

得到错误:

FAILED CONFIGURATION:@BeforeMethod setUp org.openqa.selenium.WebDriverException:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置;有关详细信息,请参阅http://code.google.com/p/selenium/wiki/ChromeDriver . 最新版本可以从http://chromedriver.storage.googleapis.com/index.html下载

我的代码:

capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
String strChromePath = System.getProperty("user.dir")
    + "\\webdrivers\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", strChromePath);
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
        capability);

在上面的代码chromedriver它自己没有被调用 .

然后我尝试使用代码:

ChromeDriverService chromeService = new ChromeDriverService.Builder()
            .usingDriverExecutable(new File("webdrivers/chromedriver.exe"))
            .usingAnyFreePort().build();
chromeService.start();
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
        capability);

在执行上面的代码时,启动可执行文件但不调用chrome . 它会抛出同样的错误 . 代码适用于Firefox . 有什么帮助吗?

2 回答

  • 0

    根据您的系统(32位/ 64位),from here下载相关的Chrome驱动程序 . 首先尝试设置ChromeDriver的属性,如下所示:

    File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
    System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
    

    然后使用此代码: -

    DesiredCapabilities capability = DesiredCapabilities.chrome();
    capability.setBrowserName("chrome");
    capability.setVersion("38.0.2125.122 m");
    WebDriver driver = new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),capability);
    

    如果不需要使用 "RemoteWebDriver" ,您可以使用以下代码进行编码:

    File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
    System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
    WebDriver driver = new ChromeDriver();
    
  • 0

    试试以下:

    WebDriver driver;
    
        System.setProperty("webdriver.chrome.driver", "properties/chromedriver.exe");
    
        driver = new ChromeDriver();
    
        driver.get("www.google.com");
    

    将chrome驱动程序放在properties文件夹中 .

相关问题