如何在自动化脚本中使用Chrome中的广告? [英] how to allow ads in chrome in my automation script?

查看:69
本文介绍了如何在自动化脚本中使用Chrome中的广告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个google登录方案,

I have a google login scenario ,

  1. 打开网站并单击Google登录
  2. 打开Goog​​le弹出窗口以添加电子邮件,然后通过然后单击登录

预期:我应该登录该网站

Expected: I should log in to the website

实际:除非开放网站设置并允许广告,否则我无法登录

Actual: I can not log in unless the open site setting and allow ads

因此,有任何方法可以添加代码以在运行脚本期间允许广告

so is there any way to add code to allow ads during running the script

推荐答案

Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.managed_default_content_settings.ads", 1); 
chromeOptions.setExperimentalOption("prefs", prefs);

使用首选项,请参阅以下所有支持的首选项:

use preference , see all supported pref at :

https://chromium.googlesource.com/chromium/src/+/66.0.3359.158/components/content_settings/core/common/pref_names.cc

注意:无头浏览器不支持首选项

Note: preference is not supported for headless browser

截至2021年2月

https://bugs.chromium.org/p/chromedriver/issues/detail?id = 1925

无头Chrome不支持偏好设置.

Headless chrome doesn't support preferrences setting .

这篇关于如何在自动化脚本中使用Chrome中的广告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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