在Selenium ChromeDriver中禁用图像 [英] Disable image in Selenium ChromeDriver

查看:276
本文介绍了在Selenium ChromeDriver中禁用图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Javascript(Node.js)禁用Chromedriver中的图像?我在任何地方都找不到这个问题的正确答案!

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

推荐答案

我确实知道这个问题已经很老了,但仍然-这是node chromedriver disable images查询的第一个Google搜索结果.所以我还是决定放手一搏.

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.

我不知道OP尝试使用的确切设置,因此我将参考自己的设置.我在运行chromedriver的预构建Selenium中使用了nightwatch.js.在我的nightwatch.conf.js文件中,我为chromedriver进行了以下设置:

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

以上设置适用于

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

并且正在稳定运行Chrome 51.0.2704.84.

and is running Chrome 51.0.2704.84 stable.

我希望能对某人有所帮助,因为我花了大约3个小时才想出这个解决方案.

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

这篇关于在Selenium ChromeDriver中禁用图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆