首页 > 解决方案 > 我的问题是我收到一个错误(等待驱动程序服务器为 Chrome 浏览器启动超时)

问题描述

我正在使用带有 Windows 10-64 位、selenium-server-standalone-3.141.59 和 selenium-java-3.141.59 的 Eclipse Luna。
我编写了一个简单的程序来访问 url。但是我收到了这个错误:

[13552:3540:0515/184943.562:ERROR:cache_util_win.cc(21)] 无法移动缓存:0 [13552:3540:0515/184943.562:ERROR:cache_util.cc(141)] 无法移动缓存文件夹 C: \Users\RChauh\AppData\Local\Google\Chrome\User Data\ShaderCache\GPUCache 到 C:\Users\RChauh\AppData\Local\Google\Chrome\User Data\ShaderCache\old_GPUCache_000 [13552:3540:0515/184943.562:错误:disk_cache.cc(185)] 无法创建缓存 [13552:3540:0515/184943.562:ERROR:shader_disk_cache.cc(623)] 着色器缓存创建失败:-2 在现有浏览器会话中打开。线程“主”org.openqa.selenium.WebDriverException 中的异常:等待驱动程序服务器启动超时。构建信息:版本:'3.141.59',修订:'e82be7d358',时间:'2018-11-14T08:25:53' 系统信息:主机:'LAPTOP-3VFBUTNB',ip:'192.168.1。http://localhost:32149/status]在 org.openqa.selenium.remote.service.DriverService.waitUntilAvailable( DriverService.java:197) ... 9 更多原因:com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout( SimpleTimeLimiter.java:156) 在 org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75) ... 10 更多

package helloWorld;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class java {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.setProperty("webdriver.chrome.driver","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
        WebDriver driver=new ChromeDriver();
        driver.get("https://www.facebook.com/");
        System.out.println("LoginPage");
        driver.quit();
    }

}

标签: seleniumwebdriverselenium-chromedriver

解决方案


您应该将webdriver.chrome.driver属性设置为指向chromedriver.exe,而不是chrome.exe

  1. 为您的 Chrome 浏览器版本下载相关的ChromeDriver
  2. 在某处解压档案
  3. 修改webdriver.chrome.driver属性以指向chromedriver.exe第 2 步
  4. 就是这样,你现在应该可以走了

如果需要,请查看ChromeDriver - Chrome 的 WebDriver -> 入门以获取更多详细信息。


直到意识到页面对象设计模式还为时不晚,它是某种形式的 Selenium 脚本最佳实践,它允许将测试逻辑与 UI 元素定义分开,从而使您的测试更易于开发,尤其是维护。查看设计模式 - 页面对象模型以获取更多详细信息和示例测试项目。


推荐阅读