升级到Chromedriver 76导致警报自动关闭

时间:2019-08-09 17:15:34

标签: python selenium selenium-webdriver webdriver selenium-chromedriver

我以前使用的Chrome驱动程序版本为74,而以前使用的Chrome浏览器版本为74。在此期间,警报没有问题。当我的浏览器自动更新到版本76时,我确实将Chrome驱动程序版本替换为76。

当我在更新后运行相同的脚本时,浏览器上的警报在代码以下(selenium中的wait.py的代码段)下运行时开始自动关闭。我确实在不同的PC上使用驱动程序74和浏览器74重新测试了相同的代码,并且工作正常。

我怀疑Chrome在最新的驱动程序中更改了警报行为,并尝试使用 chrome驱动程序选项中的以下语句,但无效。      “ profile.managed_default_content_settings.popups”:0,

弹出式窗口在以下代码的“ value = method(self._driver)”行处被关闭。

def until(self, method, message=''):
    """Calls the method provided with the driver as an argument until the \
    return value is not False."""
    screen = None
    stacktrace = None

    end_time = time.time() + self._timeout
    while True:
        try:
            value = method(self._driver)
            if value:
                return value
        except self._ignored_exceptions as exc:
            screen = getattr(exc, 'screen', None)
            stacktrace = getattr(exc, 'stacktrace', None)
        time.sleep(self._poll)
        if time.time() > end_time:
            break
    raise TimeoutException(message, screen, stacktrace)

使用的chrome选项:

  self._chromeoptions = Options
    self._chromeops = webdriver.ChromeOptions()
    prefs = {"download.default_directory": mainpath + r"\bin\download_files",
             "profile.default_content_setting_values.geolocation": 1,
             "download.prompt_for_download": False,
             'credentials_enable_service': False,
             'profile': {
                 'password_manager_enabled': False
             },
             "applicationCacheEnabled": True,
             "safebrowsing": {"enabled": True, "malware": {"enabled": True}}}
    self._caps = DesiredCapabilities.CHROME
    self._chromeops.add_experimental_option("prefs", prefs)
    self._caps.setdefault("pageLoadStrategy", "normal")
    self._chromeops.add_experimental_option("excludeSwitches", ["ignore-certificate-errors", "enable-automation"])
    self._chromeops.add_argument("--start-maximized")
    self._chromeops.add_argument("--disable-plugins")
    self._chromeops.add_argument("--disable-extensions")
    self._chromeops.set_capability('unexpectedAlertBehaviour', "ignore")
    self._chromeops.add_experimental_option("useAutomationExtension", False)

其他详细信息:

方法调用功能,直到...

         def wait_till_inactive_delay(self, xpath, delay=20):
             xpath = self.generate_xpath_structure(xpath)
             WebDriverWait(self.driver, delay, ignored_exceptions=    [NoSuchElementException]).until(expected_conditions.invisibility_of_element_located((By.XPATH, xpath)))

使用旧的chromedriver,当有警报并且调用了上述功能时,它将忽略并继续执行,但是现在当浏览器中打开警报并且调用了上述方法时,警报将被关闭。

我希望chrome浏览器/驱动程序允许用户使用switch_to_alert.accpet()接受弹出窗口,而不是关闭弹出窗口。

1 个答案:

答案 0 :(得分:2)

(''unhandledPromptBehavior',“忽略”)

所需的功能已忽略弹出窗口