Disable image in Selenium ChromeDriver

后端 未结 1 1170
面向向阳花
面向向阳花 2021-01-24 00:59

Is there a way to disable images in Chromedriver with Javascript ( Node.js )? I couldn\'t find a proper answer to this question anywhere!

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-24 01:44

    I do realise this question is quite old, but still - it is the first Google search result for the node chromedriver disable images query. So I decided to give it a go anyway.

    I don't know the exact setup the OP was trying to use, so I'll refer to my own. I'm using nightwatch.js with pre-built Selenium running chromedriver. In my nightwatch.conf.js file I have the following setup for the chromedriver:

    module.exports = {  
      "test_settings": {
        "default": {
          ...
          "desiredCapabilities": {
            "browserName": "chrome",
            "javascriptEnabled": true,
            "acceptSslCerts": true,
            "chromeOptions": {
              "args": ["disable-web-security"],
              "prefs": {
                "profile.managed_default_content_settings.images": 2
              }
            }
          }
        }
      }
    };
    

    The setup above works with

    "chromedriver": "^2.21.2",
    "selenium-server": "^2.53.0"
    

    and is running Chrome 51.0.2704.84 stable.

    I hope that helps someone, as I lost about 3 hours trying to come up with this solution.

    0 讨论(0)
提交回复
热议问题