Javascript: Disable Images In Selenium Chromedriver
Because Webdriver waits for the entire page to load before going on to the next line, I want to disable images will speed things up when the network is slow. This is the example js
Solution 1:
On a high level, I see some solutions:
- set
profile.managed_default_content_settings.images
to2
(I can't find the corresponding chromedriver documentation, but you can google it). - Set up a proxy. Connect to your page via a proxy that returns empty data when asking for an image file.
- load the browser with a browser plugin that does this for you. Something (a bit like ad-blocked works) might be available already. (con: browser-specific solution)
Solution 2:
Here I give you code for not loading image.
from selenium import webdriver
from selenium.webdriver.common.keysimportKeysfrom selenium.webdriver.chrome.optionsimportOptions
chrome_options = Options()
chrome_options.add_experimental_option( "prefs", {'profile.managed_default_content_settings.images': 2})
driver = webdriver.Chrome("chromedriver.exe",chrome_options=chrome_options)
Solution 3:
You can pass an options
object to WebdriverJS' Builder
that disables images:
{
prefs: {
profile: {
managed_default_content_settings: {
images: 2
}
}
}
}
The complete example is:
const chromeDesktop = {
prefs: {
profile: {
managed_default_content_settings: {
images: 2
}
}
}
};
const { By, Builder, until } = require('selenium-webdriver');
const driver = newBuilder().withCapabilities(chromeDesktop).build();
This definitely worked for me.
Post a Comment for "Javascript: Disable Images In Selenium Chromedriver"