【问题标题】:How to address "The constructor ChromeDriver(Capabilities) is deprecated" and WebDriverException: Timed out error with ChromeDriver and Chrome如何解决“不推荐使用构造函数 ChromeDriver(Capabilities)”和 WebDriverException:ChromeDriver 和 Chrome 超时错误
【发布时间】:2018-11-23 06:43:35
【问题描述】:

我正在尝试如下配置默认下载目录,它可以正常工作,但我遇到了两个问题:

    String exePath = "src\\Drivers\\chromedriver.exe";
    System.setProperty("webdriver.chrome.driver", exePath);
    String downloadFilepath = "U:\\Data\\Download";
    HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
    chromePrefs.put("profile.default_content_settings.popups", 0);
    chromePrefs.put("download.default_directory", downloadFilepath);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", chromePrefs);
    DesiredCapabilities cap = DesiredCapabilities.chrome();
    cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    cap.setCapability(ChromeOptions.CAPABILITY, options);
    driver = new ChromeDriver(cap);
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
  1. 它告诉我 构造函数 ChromeDriver(Capabilities) 是 已弃用
  2. 当我多次重播测试时,它恰好有一个 Webdrive TimeOut 异常

    juin 13, 2018 5:23:27 PM org.openqa.selenium.remote.DesiredCapabilities chrome
    INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
    FAILED CONFIGURATION: @BeforeMethod beforeMethod
    org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
    Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
    System info: host: 'PB02-VD037', ip: '10.143.73.85', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_171'
    Driver info: driver.version: ChromeDriver
    

【问题讨论】:

  • 你的chrome版本和chromedriver版本是多少?
  • Chrome:版本 66.0.3359.117(官方构建)(64 位)Chromedriver:2.37

标签: selenium selenium-webdriver selenium-chromedriver chrome-options mutablecapabilities


【解决方案1】:

看来你快到了。您需要使用 MutableCapabilities 类中的方法 merge()DesiredCapabilities 类型的对象合并到 ChromeOptions 类型的对象中并启动 WebDriverWebClient 实例通过传递 ChromeOptions 对象如下:

String exePath = "src\\Drivers\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", exePath);
String downloadFilepath = "U:\\Data\\Download";
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
options.merge(cap);
driver = new ChromeDriver(options);

【讨论】:

    猜你喜欢
    • 2020-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多