弹窗类型
1. div弹窗
div弹窗不需要切换iframe,元素需要二次定位,python写法为:
driver.find_element_by_class_name("tang-pass-footerBar").find_element_by_id('TANGRAM__PSP_10__footerULoginBtn').click()
实例如下:
selenium提供switch_to_alert方法:捕获弹出对话框(可以定位alert、confirm、prompt对话框)
switch_to_alert() --定位弹出对话框
text() --获取对话框文本值
accept() --相当于点击“确认”
dismiss() --相当于点击“取消”
send_keys() --输入值(alert和confirm没有输入对话框,所以就不用能用了,只能使用在prompt里)
1.定位alert弹出框
注意:获取alert弹出框时使用 x = m.switch_to.alert,而不是 x = m.switch_to.alert(),否则会提示错误:TypeError: 'Alert' object is not callable(对象不能用函数形式调用)
2.定位confirm弹出框
3.定位prompt弹出框