Làm cách nào để vô hiệu hóa hình ảnh trong Google chrome khi sử dụng hình ảnh thông qua Selenium và C#?Tắt hình ảnh trong Selenium Google ChromeDriver
Tôi đã thử 6 cách và không có cách nào hoạt động. Tôi thậm chí đã thử câu trả lời trên câu hỏi this StackOverflow, tuy nhiên tôi nghĩ rằng thông tin trong đó đã lỗi thời.
- Chrome tài xế: V2.2
- Chrome phiên bản: V29.0.1547.66 m
- Selenium: V2.35
Tất cả những nỗ lực tôi đã thực hiện không gây ra trường hợp ngoại lệ , họ chạy bình thường nhưng vẫn hiển thị hình ảnh:
Cố gắng 1:
ChromeOptions co = new ChromeOptions();
co.AddArgument("--disable-images");
IWebDriver driver = new ChromeDriver(co);
Cố gắng 2:
DesiredCapabilities capabilities = DesiredCapabilities.Chrome();
capabilities.SetCapability("chrome.switches", new string[1] { "disable-images" });
Nỗ lực 3:
ChromeOptions co = new ChromeOptions();
co.AddAdditionalCapability("chrome.switches", new string[1] { "disable-images" });
Nỗ lực 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);
}
Nỗ lực 5:
ChromeOptions options = new ChromeOptions();
options.AddAdditionalCapability("profile.default_content_settings", 2);
Cố 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);
Bạn đã thử giải pháp trong câu hỏi đó chưa? Bạn đang sử dụng phiên bản ChromeDriver nào? Xin vui lòng gửi các cách (mã chính xác) mà bạn đã thử và cách nó không hoạt động (nếu nó chỉ đơn giản là không vô hiệu hóa các hình ảnh hoặc nếu nó đã ném một lỗi). – Arran
có thể trùng lặp của [Tắt hình ảnh trong Selenium ChromeDriver] (http://stackoverflow.com/questions/9433109/disable-images-in-selenium-chromedriver) – jww