2016-08-02 24 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);