Changing Chrome's settings with Selenium

五迷三道 提交于 2019-12-12 00:35:34

问题


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:


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.



来源:https://stackoverflow.com/questions/36876397/changing-chromes-settings-with-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!