6.alert.confirm.prompt弹窗
Posted tofuir-miss
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了6.alert.confirm.prompt弹窗相关的知识,希望对你有一定的参考价值。
# 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>
以上是关于6.alert.confirm.prompt弹窗的主要内容,如果未能解决你的问题,请参考以下文章