python处理弹窗,复选框,嵌套框架

file_path='file:///'+os.path.abspath('case.html')
用浏览器的方式打开一个页面+获取绝对路径

 

处理弹窗:

dr=webdriver.IE()
dr.switch_to_alert() 处理弹窗
dr.switch_to_alert().accept() 确定
dr.switch_to_alert().dismiss() 取消

 

复选框:

定位一组元素,定位所有的复选框,然后再来筛选
inputs=dr.find_elemnts_by_tag_name("input")
for i in inputs:
if i.get_attribute("type")=="checkbox" and i.get_attribute("id")="c1":
i.click()

 

嵌套框架:

打开网页源码看到有标签“iframe”就代表有嵌套

先找到外部框架
driver.switch_to_frame("f1")
再找到内部框架
driver.switch_to_frame("f2")
再正常操作元素
driver.find_element_by_id("kw").send_keys("selenium")

posted on 2019-12-12 18:03  wenjingtester  阅读(576)  评论(0编辑  收藏  举报