标签:drive 输入 webdriver confirm bdr key import 操作 ext
# coding:utf-8
# alert操作
from selenium import webdriver
import time
url = "file:///E:/Selenium/弹窗.html"
driver = webdriver.Chrome()
driver.get(url)
time.sleep(4)
# driver.find_element_by_id("alert").click()
driver.find_element_by_id("prompt").click()
time.sleep(3)
# t = driver.switch_to.alert
# # 打印警告框文本内容
# print(t.text)
# # 点警告框确认按钮
# t.accept()
# prompt操作
t = driver.switch_to.alert
# 打印警告框文本内容
print(t.text)
t.send_keys(‘send keys msg‘)
time.sleep(2)
t.accept()
# html示例代码
# <html>
#
# <head>
#
# <title>Alert</title>
#
# </head>
#
# <body>
#
# <input id = "alert" value = "alert" type = "button" onclick = "alert(‘您关注了yoyoketang吗?‘);"/>
#
# <input id = "confirm" value = "confirm" type = "button" onclick = "confirm(‘确定关注微信公众号:yoyoketang?‘);"/>
#
# <input id = "prompt" value = "prompt" type = "button" onclick = "var name = prompt(‘请输入微信公众号:‘,‘yoyoketang‘); document.write(name) "/>
#
# </body>
#
# </html>
标签:drive 输入 webdriver confirm bdr key import 操作 ext
原文地址:https://www.cnblogs.com/Tofuir-miss/p/13151553.html