1.Alert 类型弹窗

driver.find_element(By.XPATH,".//button[@id='b1']").click()
time.sleep(1)
alert = driver.switch_to.alert #获取弹窗对象
a = alert.text
print(a)

alert.accept() #点击确认

2.Confirm 类型弹窗

driver.find_element(By.XPATH,".//button[@id='b2']").click()
time.sleep(1)
confirm = driver.switch_to.alert #获取弹窗对象
print(confirm.text)

time.sleep(1)
confirm.accept()
confirm.dismiss() #取消按钮

3.Prompt 类型弹窗

driver.find_element(By.XPATH,".//button[@id='b3']").click()
time.sleep(1)
prompt = driver.switch_to.alert #获取弹窗对象
print(prompt.text)
time.sleep(1)
prompt.send_keys('python nihao')
time.sleep(1)
prompt.accept()
# confirm.dismiss() #取消按钮