首页 > 其他 > 详细

Selenium学习笔记||八、Frame的处理

时间:2019-05-16 14:33:12      阅读:129      评论:0      收藏:0      [点我收藏+]

一、切换到frame里边

  driver.switch_to.frame(frame_reference)

  1. frame元素的name属性或ID属性

  2. 索引值(从0开始) 0 (不是下级)

  3. frame所对应的WebElement

转自:https://www.cnblogs.com/technologylife/p/5851496.html
reference是传入的参数,用来定位frame,可以传入id、name、index以及selenium的WebElement对象,假设有如下HTML代码 index.html:
<html lang="en"> <head> <title>FrameTest</title> </head> <body> <iframe src="a.html" id="frame1" name="myframe"></iframe> </body> </html> 想要定位其中的iframe并切进去,可以通过如下代码: from selenium import webdriver driver = webdriver.Firefox() driver.switch_to.frame(0) # 1.用frame的index来定位,第一个是0 # driver.switch_to.frame("frame1") # 2.用id来定位 # driver.switch_to.frame("myframe") # 3.用name来定位 # driver.switch_to.frame(driver.find_element_by_tag_name("iframe")) # 4.用WebElement对象来定位

 

二、切换回主HTML里边

  driver.switch_to.default_content()

 

三、切换到上层

  driver.switch_to.parent_frame()

 

 

注意那些会变的ID

Selenium学习笔记||八、Frame的处理

原文:https://www.cnblogs.com/Lixinhang/p/10875259.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!