• Python selenium Chrome正在受到自动软件的控制 disable-infobars无效 的解决方法


    问题解决

    前两天更新了google浏览器版本,今天运行以前的脚本,发现options一个参数的配置不生效了。

    运行了几次都发现该参数没有生效,也检查了自己的代码参数,没有写错,于是就有了这一波“网中寻求答案”的操作。

    苦寻不易,还真就找到了答案,详细可参见该地址的答案:https://help.applitools.com/hc/en-us/articles/360007189411--Chrome-is-being-controlled-by-automated-test-software-notification,里面有详细解答。

    我也针对自己的代码进行了修改,也已生效。代码修改如下:

    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
    driver = webdriver.Chrome(options=chrome_options)

    老版本浏览器的写法还是如下所示代码:

    chrome_options.add_argument('--disable-infobars')  # 不显示正在受自动化软件控制

    java代码修改如下:

    ChromeOptions options = new ChromeOptions(); 
    options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"}); 
    DesiredCapabilities caps = DesiredCapabilities.chrome(); 
    caps.setCapability(ChromeOptions.CAPABILITY, options); 
    WebDriver driver = new RemoteWebDriver(caps);

    options参数

    统计了一些常用参数,如下所示:

    options.add_argument('--disable-infobars')  # 禁止策略化
    options.add_argument('--no-sandbox')  # 解决DevToolsActivePort文件不存在的报错
    options.add_argument('window-size=1920x3000')  # 指定浏览器分辨率
    options.add_argument('--disable-gpu')  # 谷歌文档提到需要加上这个属性来规避bug
    options.add_argument('--incognito')  # 隐身模式(无痕模式)
    options.add_argument('--disable-javascript')  # 禁用javascript
    options.add_argument('--start-maximized')  # 最大化运行(全屏窗口),不设置,取元素会报错
    options.add_argument('--hide-scrollbars')  # 隐藏滚动条, 应对一些特殊页面
    options.add_argument('blink-settings=imagesEnabled=false')  # 不加载图片, 提升速度
    options.add_argument('--headless')  # 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败
    options.binary_location = r"C:Program Files (x86)GoogleChromeApplicationchrome.exe"  # 手动指定使用的浏览器位置
    options.add_argument('lang=en_US') # 设置语言
    options.add_argument('User-Agent=Mozilla/5.0 (Linux; U; Android 8.1.0; zh-cn; BLA-AL00 Build/HUAWEIBLA-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/8.9 Mobile Safari/537.36')
    options.add_argument('--headless')  # 浏览器不提供可视化页面
    prefs = {"":""}
    prefs["credentials_enable_service"] = False
    prefs["profile.password_manager_enabled"] = False
    chrome_option_set.add_experimental_option("prefs", prefs) # 屏蔽'保存密码'提示框
  • 相关阅读:
    查询两门及其以上不及格课程的同学的学号,姓名及其平均成绩 从SC表中选取score小于60的,并group by sid,having count 大于1
    SQL经典实例书上的数据代码
    mysql练习题
    mysql中alter语句
    如何解决SSH登录Solaris主机速度慢的问题
    Solaris10安装配置LDAP(iPlanet Directory Server )
    Oracle 11g oracle 用户密码过期问题 (ZT)
    Changing Controller Numbers in Solaris
    SPARC T4 RAID Setup (ZT)
    Oracle11g 配置DG broker
  • 原文地址:https://www.cnblogs.com/hong-fithing/p/12796602.html
Copyright © 2020-2023  润新知