Alert Test (sahitest.com)
![](https://img.haomeiwen.com/i3968643/3a3976cb38080038.png)
image.png
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://sahitest.com/demo/alertTest.htm')
driver.find_element(By.NAME,'b1').click()
# 使用alert.text获取弹框的文字
print(driver.switch_to.alert.text)
# 点击确定
driver.switch_to.alert.accept()
time.sleep(3)
driver.close()
![](https://img.haomeiwen.com/i3968643/321773bd0f322e34.png)
image.png
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://sahitest.com/demo/confirmTest.htm')
driver.find_element(By.NAME,'b1').click()
time.sleep(3)
# 使用alert.text获取弹框的文字
print(driver.switch_to.alert.text)
# 点击确定
driver.switch_to.alert.accept()
time.sleep(3)
driver.close()
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://sahitest.com/demo/confirmTest.htm')
driver.find_element(By.NAME,'b1').click()
time.sleep(3)
# 使用alert.text获取弹框的文字
print(driver.switch_to.alert.text)
# # 点击确定
# driver.switch_to.alert.accept()
# 点击取消
driver.switch_to.alert.dismiss()
time.sleep(3)
driver.close()
![](https://img.haomeiwen.com/i3968643/a5f1356cd22b896a.png)
image.png
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://sahitest.com/demo/promptTest.htm')
driver.find_element(By.NAME,'b1').click()
time.sleep(3)
driver.switch_to.alert.send_keys("Alert Test")
# # 点击确定
driver.switch_to.alert.accept()
# # 点击取消
# driver.switch_to.alert.dismiss()
time.sleep(3)
driver.close()
网友评论