Selenium UnhandledPromptBehavior

Posted in :

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"

相關文章:

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *