Jak można wyłączyć obrazy w Google Chrome podczas używania go przez Selenium i C#?Wyłączanie obrazów w Selenium Google ChromeDriver
Próbowałem 6 sposobów i żaden nie działał. Próbowałem nawet odpowiedzi na pytanie o StackOverflow this, jednak uważam, że informacje w nim zawarte są nieaktualne.
- Chrome kierowcy: V2.2
- Chrome wersja: V29.0.1547.66 m
- Selen: V2.35
Wszystkie próby zrobiłem nie powodują wyjątki uruchom normalnie ale nadal wyświetlać obrazy:
próba 1:
ChromeOptions co = new ChromeOptions();
co.AddArgument("--disable-images");
IWebDriver driver = new ChromeDriver(co);
Próba 2:
DesiredCapabilities capabilities = DesiredCapabilities.Chrome();
capabilities.SetCapability("chrome.switches", new string[1] { "disable-images" });
Próba 3:
ChromeOptions co = new ChromeOptions();
co.AddAdditionalCapability("chrome.switches", new string[1] { "disable-images" });
Próba 4:
var imageSetting = new Dictionary<string, object>();
imageSetting.Add("images", 2);
Dictionary<string, object> content = new Dictionary<string, object>();
content.Add("profile.default_content_settings", imageSetting);
var prefs = new Dictionary<string, object>();
prefs.Add("prefs", content);
var options = new ChromeOptions();
var field = options.GetType().GetField("additionalCapabilities", BindingFlags.Instance | BindingFlags.NonPublic);
if (field != null)
{
var dict = field.GetValue(options) as IDictionary<string, object>;
if (dict != null)
dict.Add(ChromeOptions.Capability, prefs);
}
Próba 5:
ChromeOptions options = new ChromeOptions();
options.AddAdditionalCapability("profile.default_content_settings", 2);
Próba 6:
Dictionary<String, Object> contentSettings = new Dictionary<String, Object>();
contentSettings.Add("images", 2);
Dictionary<String, Object> preferences = new Dictionary<String, Object>();
preferences.Add("profile.default_content_settings", contentSettings);
DesiredCapabilities caps = DesiredCapabilities.Chrome();
caps.SetCapability("chrome.prefs", preferences);
Czy wypróbowałeś rozwiązanie w tym pytaniu? Z której wersji ChromeDriver korzystasz? Opublikuj sposoby (dokładny kod), które wypróbowałeś i jak one nie działały (jeśli po prostu nie wyłączyły obrazów lub jeśli wystąpił błąd). – Arran
możliwy duplikat [Wyłącz obrazy w Selenium ChromeDriver] (http://stackoverflow.com/questions/9433109/disable-images-in-selenium-chromedriver) – jww