0

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

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'],
    }],

4

1 回答 1

0

这是一种解决方法,但是,如果您使用 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')
于 2021-04-01T04:54:30.763 回答