請服用 selenuum
def handle_alert_popup(self):
# Step 1: wait for alert window
# prevent:
# Message: unexpected alert open: {Alert text :
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
element = WebDriverWait(self.driver, 10).until(
EC.alert_is_present()
)
# Step 2: click ok
alert = self.driver.switch_to_alert()
alert.accept()
Further Reading
- Python Main Page - Web Automation 章節 (view)