from selenium import webdriver
import os
import time
# 數(shù)據(jù)初始化
base_url = os.path.dirname(__file__) + '/html/' ++ 'alert.html'
browser = webdriver.Chrome()
# 打開瀏覽器
browser.get(base_url)
browser.maximize_window()
# 定位并點(diǎn)擊 alert 按鈕
browser.find_element_by_id('alert').click()
time.sleep(3)
# 確認(rèn)alert
browser.switch_to.alert.accept()
time.sleep(3)
# 定位并點(diǎn)擊 confirm 按鈕
browser.find_element_by_id('confirm').click()
time.sleep(3)
# 確認(rèn)confirm
browser.switch_to.alert.accept()
time.sleep(3)
# 定位并點(diǎn)擊 confirm 按鈕
browser.find_element_by_id('confirm').click()
time.sleep(3)
# 取消 confirm
browser.switch_to.alert.dismiss()
time.sleep(3)
# 定位并點(diǎn)擊 prompt 按鈕
browser.find_element_by_id('prompt').click()
time.sleep(3)
# 往prompt窗口中輸入值
browser.switch_to.alert.send_keys("test")
time.sleep(3)
# 確認(rèn)prompt
browser.switch_to.alert.accept()
time.sleep(3)
# 退出瀏覽器
browser.quit()