如何解决“不赞成使用构造函数ChromeDriver(Capabilities)"的问题,和WebDriverException:ChromeDriver和Chrome超时错误 [英] How to address "The constructor ChromeDriver(Capabilities) is deprecated" and WebDriverException: Timed out error with ChromeDriver and Chrome

本文介绍了如何解决“不赞成使用构造函数ChromeDriver(Capabilities)"的问题,和WebDriverException:ChromeDriver和Chrome超时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to config the default download directory as below, it's works correctly but I'm having two issues :

    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超时异常

  1. It's telling me that The constructor ChromeDriver(Capabilities) is deprecated
  2. When I replay the test several times it happens to have a Webdrive TimeOut exception

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

推荐答案

似乎您快到了.您需要使用方法

It seems you were almost there. You need to use the method merge() from MutableCapabilities Class to merge the DesiredCapabilities type of object into ChromeOptions type object and initiate the WebDriver and WebClient instance by passing the ChromeOptions object as follows :

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);

这篇关于如何解决“不赞成使用构造函数ChromeDriver(Capabilities)"的问题,和WebDriverException:ChromeDriver和Chrome超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆