UnhandledPromptBehavior 參數用途:
Specifies the behavior of handling unexpected alerts
參數值有這幾個:
- Accept
Accept unexpected alerts. - AcceptAndNotify
Accepts unexpected alerts and notifies the user that the alert has been accepted by throwing an UnhandledAlertException - Default
Indicates the behavior is not set. - Dismiss
Dismiss unexpected alerts. - DismissAndNotify
Dismisses unexpected alerts and notifies the user that the alert has been dismissed by throwing an UnhandledAlertException - Ignore
Ignore unexpected alerts, such that the user must handle them.
Max測試,預設值應該是 DismissAndNotify。
設定方式:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities
import DesiredCapabilities
caps = DesiredCapabilities().CHROME
caps["unhandledPromptBehavior"] = "dismiss and notify"
driver = webdriver.Chrome(desired_capabilities=caps, executable_path=r'C:\path\to\chromedriver.exe') driver.get("http://google.com")
範例2:
options = uc.ChromeOptions()
options.page_load_strategy = 'eager'
options.unhandled_prompt_behavior = "accept"
相關文章:
- The Desired Capabilities implementation.
https://github.com/SeleniumHQ/selenium/blob/master/py/selenium/webdriver/common/desired_capabilities.py - known prompt handling approaches table
https://www.w3.org/TR/webdriver/#dfn-dismiss-and-notify-state