Changing Chrome's settings with Selenium

2019-09-06 05:31发布

I'm working on Chrome with Selenium and I'm looking to change a few settings within Chrome using the webdriver. Using Google and this site, I was able to get most of the settings working. However, a few more seem to escape me and hopefully I can get the answers here. I'm looking to alter the settings before launching the browser, such as using ChromeOptions, rather than using automation to navigate the settings page.

The settings I'm looking to change are as follows:

  • Disable Javascript
  • Disable the microphone
  • Change the home page
  • Altering the default search engine in the Omnibox

These 4 are giving me the most issues. Any help?

1条回答
仙女界的扛把子
2楼-- · 2019-09-06 06:22

Perhaps this List of Chromium Command Line Switches will help. E.g.

DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability("chrome.switches", Arrays.asList("--disable-javascript"));

And

Map<String, Object> preferences = Maps.newHashMap();
preferences.put( "browser.startup.homepage", "http://my.home.page" );
preferences.put( "browser.startup.page", START_WITH_HOME_PAGE );
capabilities.setCapability( ChromeOptions.CAPABILITY, preferences );
ChromeDriver driver = new ChromeDriver( capabilities );

Update

My guess is that the following

"import_search_engine": true

from Configuring other parameters will cause Chrome to ask you to select a search engine when it opens.

Turning off JavaScript makes chrome pretty much a no-op; I do not think that the option is supported. As far as microphones, that is more a system option. A search of about:config for microphone came up empty.

查看更多
登录 后发表回答