【问题标题】:Changing Chrome's settings with Selenium使用 Selenium 更改 Chrome 的设置
【发布时间】:2016-04-26 21:49:18
【问题描述】:

我正在使用 Selenium 开发 Chrome,我希望使用 webdriver 在 Chrome 中更改一些设置。使用谷歌和这个网站,我能够让大部分设置正常工作。然而,还有一些似乎逃脱了我,希望我能在这里得到答案。我希望在启动浏览器之前更改设置,例如使用ChromeOptions,而不是使用自动化来导航设置页面。

我要更改的设置如下:

  • 禁用Javascript
  • 禁用麦克风
  • 更改主页
  • 更改多功能框中的默认搜索引擎

这 4 个问题给我的问题最多。有什么帮助吗?

【问题讨论】:

    标签: google-chrome selenium selenium-webdriver selenium-chromedriver


    【解决方案1】:

    也许这个List of Chromium Command Line Switches 会有所帮助。例如

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

    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 );
    

    更新

    我的猜测是以下

    "import_search_engine": true
    

    来自Configuring other parameters 将导致 Chrome 在打开时要求您选择搜索引擎。

    关闭 JavaScript 使 chrome 几乎成为无操作;我认为不支持该选项。就麦克风而言,这更像是一个系统选项。搜索 about:config 的麦克风是空的。

    【讨论】:

    • 我检查了那个页面,我只看到设置主页的选项,这很有用,所以谢谢你。但是,--disable-javascript 标志于 2014 年 11 月 14 日被删除,如older version of the page 所示。当前仍然存在的--disable-javascript-harmony-shipping 标志并没有完全禁用javascript。对于三个目前未解决的问题,我仍然需要帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-25
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    • 1970-01-01
    • 2013-09-09
    相关资源
    最近更新 更多