2016-06-03 5 views
3

Chrome Plugin pop upWie Chrome Plugins in Selenium WebDriver mit Java

Wenn ich der Ausführung meines Automation-Code für diese Anwendung der oben Popup angezeigt deaktivieren. Jetzt müsste ich wissen, wie man das PDF Viewer Plugin in Selenium WebDriver mit Java deaktiviert.

Hier ist, was ich gerade benutze, die nicht funktioniert.

DesiredCapabilities capabilities = DesiredCapabilities 
           .chrome(); 
         ChromeOptions options = new ChromeOptions(); 
         options.addArguments(new String[] { "test-type" }); 
         options.addArguments(new String[] { "disable-extensions" }); 


String pluginToDisable = "Chrome PDF Viewer"; 
         options.addArguments("plugins.plugins_disabled", pluginToDisable); 


         capabilities.setCapability("chrome.binary", 
           chromeDriver.getAbsolutePath()); 
         capabilities.setCapability(ChromeOptions.CAPABILITY, 
           options); 
         options.addArguments("--lang=en-gb"); 
         GlobalVars.driver = new ChromeDriver(capabilities); 
+0

Ich habe es mit anderer Kombination auch ausprobiert. Funktioniert immer noch nicht. Option # 1: options.addArguments ("disable-plugins"); GlobalVars.driver = neuer ChromeDriver (Optionen); Option # 2: Karte prefs = new HashMap <>(); prefs.put ("plugins.plugins_disabled", "Chrome PDF Viewer"); \t \t \t \t \t options.setExperimentalOption ("prefs", Einstellungen); GlobalVars.driver = neuer ChromeDriver (Optionen); –

Antwort

3

Hier ist ein Beispiel Flash und PDF-Viewer mit Selen/Chrome zu deaktivieren:

ChromeOptions options = new ChromeOptions(); 
Map<String, Object> preferences = new Hashtable<String, Object>(); 
options.setExperimentalOption("prefs", preferences); 

// disable flash and the PDF viewer 
preferences.put("plugins.plugins_disabled", new String[] { 
    "Adobe Flash Player", 
    "Chrome PDF Viewer" 
}); 

// launch the browser and navigate to the page 
ChromeDriver driver = new ChromeDriver(options); 
driver.get("https://www.google.co.uk"); 
0

--- Das für mich-

HashMap<String, Object> chromePrefs = new HashMap<String, Object>(); 
        chromePrefs.put("plugins.plugins_disabled", new String[] {"Adobe Flash Player", "Chrome PDF Viewer"}); 
        chromePrefs.put("profile.default_content_settings.popups", 0); 
        ChromeOptions options = new ChromeOptions(); 
        options.setExperimentalOption("prefs", chromePrefs); 
        DesiredCapabilities cap = DesiredCapabilities.chrome(); 
        cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); 
        cap.setCapability(ChromeOptions.CAPABILITY, options); 
        GlobalVars.driver = new ChromeDriver(cap); 
5

Aktualisiert für Chrome V gearbeitet : 57

Diese Lösung funktioniert nicht mehr.

ist hier eine gültige Implementierung in C#:

 var options = new ChromeOptions(); 
     // This was a PAIN. If this ever does not work, here is how I got the preference name: 
     // 1. Navigate to : chrome://settings/content 
     // 2. Scroll to the bottom "PDF Documents" section 
     // 3. Right-Click and inspect element on the check box titled "Open PDF files in the default PDF viewer application" 
     // 4. The preference name is the pref key for the input, in this case: pref="plugins.always_open_pdf_externally" 
     options.AddUserProfilePreference("plugins.always_open_pdf_externally", true); 

     // The constructor must be pointed to the chrome driver .exe 
     // Or you must set a PATH variable pointing to the location 
     using (var driver = new ChromeDriver(options)) 
     { 
     .......... 
+0

arbeitete für mich. Vielen Dank! – kb4shubham

0

Da Chrome-Einstellungen Seite auch ein Web-App ist, können Sie programmatisch die Einstellungsseite kriechen und den PDF-Viewer deaktivieren. Hier ist ein Beispiel Python-Code:

browser = webdriver.Chrome("./chromedriver")  
browser.get("chrome://settings-frame/content") 
pdf_section = browser.find_element_by_id("pdf-section") 
pdf_disable_checkbox = pdf_section.find_element_by_tag_name("input") 
if not pdf_section.is_selected(): 
    pdf_disable_checkbox.click() 
0

Es scheint, "plugins.plugins_disabled" oder "plugins.plugins_list" nicht mehr funktioniert. Die Option "plugins.always_open_pdf_externally" funktionierte für mich (mheirendt's Lösung). Beispiel in Java:

ChromeOptions co = new ChromeOptions(); 
Map<String,Object> prefs = new HashMap<>(); 
prefs.put("plugins.always_open_pdf_externally", true); 
co.setExperimentalOption("prefs", prefs); 
WebDriver driver = new ChromeDriver(co); 
Verwandte Themen