码迷,mamicode.com
首页 > 其他好文 > 详细

6.alert.confirm.prompt弹窗

时间:2020-06-17 13:01:10      阅读:50      评论:0      收藏:0      [点我收藏+]

标签: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>

6.alert.confirm.prompt弹窗

标签:drive   输入   webdriver   confirm   bdr   key   import   操作   ext   

原文地址:https://www.cnblogs.com/Tofuir-miss/p/13151553.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!