2016-08-02 58 views
-3

我想设置多个期望的功能,为硒驱动程序对象的一个​​实例。 我想让浏览器先设置文件的下载位置 ,然后在Chrome浏览器中禁用pdf查看器插件。任何人都可以协助Selenium多个期望的功能设置

禁用PDF浏览器插件的代码片段:

DesiredCapabilities caps = DesiredCapabilities.chrome(); 
    Map<String, Object> preferences = new HashMap<String, Object>(); 
    preferences.put("plugins.plugins_disabled", new String[] { "Chrome PDF Viewer" }); 
    ChromeOptions options1 = new ChromeOptions(); 
    options1.setExperimentalOption("prefs", preferences); 
    caps.setCapability(ChromeOptions.CAPABILITY, options1); 

设置下载位置的代码片段:

Map<String, Object> prefs = new HashMap<String, Object>(); 
    prefs.put("download.default_directory", "C:\\Users\\user\\Downloads\\"); 
    ChromeOptions options = new ChromeOptions(); 
    options.setExperimentalOption("prefs", prefs); 
    caps.setCapability(ChromeOptions.CAPABILITY, options); 
+2

这完全不清楚您要问什么。请阅读[问]。如果您对英文不熟悉,请考虑使用Google翻译器。 – xenteros

+0

我想为Chrome驱动程序的一个实例设置多个所需的功能。我想设置Chrome浏览器下载位置,并在浏览器实例中禁用PDF查看器。 –

+0

发布您尝试过的代码。 – tak3shi

回答

0

只是因为你想多能力不创建两个单独的ChromeOptions。这就是他们拍地图的原因。只需将两个键值对放在一张地图中,然后将其添加到选项对象中即可......例如:

DesiredCapabilities caps = DesiredCapabilities.chrome(); 
Map<String, Object> preferences = new HashMap<>(); 
preferences.put("plugins.plugins_disabled", new String[] { "Chrome PDF Viewer" }); 
preferences.put("download.default_directory", "C:\\Users\\user\\Downloads\\"); 
ChromeOptions options = new ChromeOptions(); 
options.setExperimentalOption("prefs", preferences); 
caps.setCapability(ChromeOptions.CAPABILITY, options);