一、弹框的类型
1、下载的弹框
2、弹框的类型:
(1)alert弹框
(2)确认性弹框
(3)输入性弹框
(4)上传性弹框
(5)frame弹框
3、实战
(1)alert弹框
地址:
file:///E:/dcs/two/selenium/%E5%BC%B9%E6%A1%86/alert%E5%BC%B9%E6%A1%86.html
from selenium import webdriver #导入selenium第三方库中webdriver
from time import sleep
dx=webdriver.Chrome() #创建一个对象来来调用谷歌浏览器的对象
dx.get("file:///E:/dcs/two/selenium/%E5%BC%B9%E6%A1%86/alert%E5%BC%B9%E6%A1%86.html") #通过对象打开浏览
tk=dx.switch_to.alert #切换弹框
tk.accept() #确认
sleep(2)
tk.accept() #确认
取消
from selenium import webdriver #导入selenium第三方库中webdriver
from time import sleep
dx=webdriver.Chrome() #创建一个对象来来调用谷歌浏览器的对象
dx.get("file:///E:/dcs/two/selenium/%E5%BC%B9%E6%A1%86/alert%E5%BC%B9%E6%A1%86.html") #通过对象打开浏览
tk=dx.switch_to.alert #切换弹框
sleep(3)
tk.dismiss() #取消
(2)确认性弹框
from time import sleep
dx=webdriver.Chrome() #创建一个对象来来调用谷歌浏览器的对象
dx.get(r"file:///E:/dcs/two/selenium/%E5%BC%B9%E6%A1%86/enter.html")
dx.find_element_by_class_name("alert").click()
tk=dx.switch_to.alert #切换弹框
sleep(3)
tk.accept()#确认
(3)输入性弹框
from selenium import webdriver #导入selenium第三方库中webdriver
from time import sleep
dx=webdriver.Chrome() #创建一个对象来来调用谷歌浏览器的对象
dx.get(r"file:///E:/dcs/two/selenium/%E5%BC%B9%E6%A1%86/prompt.html")
dx.find_element_by_class_name("alert").click()
tk=dx.switch_to.alert #切换弹框
tk.send_keys("hz")
tk.accept()
(4)上传性弹框
链接:
file:///E:/dcs/two/selenium/%E5%BC%B9%E6%A1%86/upload_file.html
from selenium import webdriver #导入selenium第三方库中webdriver
from time import sleep
dx=webdriver.Chrome() #创建一个对象来来调用谷歌浏览器的对象
dx.get(r"file:///E:/dcs/two/selenium/%E5%BC%B9%E6%A1%86/upload_file.html")
dx.find_element_by_id("file").send_keys(r"E:\dcs\two\selenium\弹框\table.html")
(5)frame弹框
from selenium import webdriver #导入selenium第三方库中webdriver
from time import sleep
dx=webdriver.Chrome() #创建一个对象来来调用谷歌浏览器的对象
dx.get(r"https://graph.qq.com/oauth2.0/show?which=Login&display=pc&response_type=code&state=84C8F7977ED7653BB9E28C6396A442A045F2A4DBBEE2D115DC961B2CB6DCC8F81DB107254144162E972769188FB4AC23&client_id=100273020&redirect_uri=https%3A%2F%2Fqq.jd.com%2Fnew%2Fqq%2Fcallback.action%3Fuuid%3Da90096cfbd274a3f9fe6123ce21a592dl")
sleep(2)
wz=dx.find_element_by_id("ptlogin_iframe")
dx.switch_to.frame(wz) #进框
dx.find_element_by_link_text("密码登录").click() #点不到
dx.switch_to.default_content() #退框
dx.find_element_by_link_text("服务协议").click() #可以点