如何在 selenium 驱动程序中禁用 chrome 权限弹出窗口

问题描述

Chrome 版本 89 并在以下设置中进行设置,但仍然没有关闭阻止其余测试用例的权限弹出窗口。 任何想法或解决方法

enter image description here

capabilities: [{
    
        // maxInstances can get overwritten per capability. So if you have an in-house Selenium
        // grid with only 5 firefox instances available you can make sure that not more than
        // 5 instances get started at a time.
        maxInstances: 1,//
        browserName: 'chrome','goog:chromeOptions': {
            // to run chrome headless the following flags are required
            // (see https://developers.google.com/web/updates/2017/04/headless-chrome)
            // args: ['--headless','--disable-gpu'],prefs: {
                'profile.managed_default_content_settings.popups' : 1,'profile.managed_default_content_settings.notifications' : 1,},args: ['--auto-open-devtools-for-tabs','disable-infobars','disable-popup-blocking','disable-notifications']
        },// If outputDir is provided WebdriverIO can capture driver session logs
        // it is possible to configure which logTypes to include/exclude.
        // excludeDriverLogs: ['*'],// pass '*' to exclude all driver session logs
        // excludeDriverLogs: ['bugreport','server'],}],

解决方法

这是一种解决方法,但是,如果您使用 Python 并且弹出窗口出现在一致的位置,您可以使用 pyautogui 单击阻止或允许按钮并关闭弹出窗口。请参阅下面的示例代码:

import pyautogui 

# ensure the Selenium-managed browser has the focus and will receive the click   
driver.switch_to.window(driver.current_window_handle) 

# moveTo the X and Y coordinate of the block or allow button
pyautogui.moveTo(1350,700) 

# click the block or allow button
pyautogui.click()

如果您需要确定 X 和 Y 坐标,以下代码可以提供帮助:

import pyautogui,sys
print('Press Ctrl-C to quit.')
try:
    while True:
        x,y = pyautogui.position()
        positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
        print(positionStr,end='')
        print('\b' * len(positionStr),end='',flush=True)
except KeyboardInterrupt:
    print('\n')

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...