Selenium3+python自动化009-iframe定位

iframe

一、frame:HTML页面中的一种框架,主要作用是在当前页面中指定区域显示另一页面元素;

 

二、操作Frame中的页面元素

定位元素:

1.id定位
driver.switch_to.frame('frame_id')

2.name定位
driver.switch_to.frame('frame_name')

3.索引
driver.switch_to.frame(0)

4.webelement对象
a=driver.find_element_by_xpath('//iframe')
driver.switch_to_frame(a)

 

嵌套frame

1.fame1中嵌套frame2:
先切换到frame1,再切换到frame2
driver.switch_to.frame('frame1')
driver.switch_to.frame('frame2')

2.从frame2返回到frame1
driver.switch_to.parent_frame()

3.回退到主文档
driver.switch_to.default_content()

猜你喜欢

转载自www.cnblogs.com/liunaixu/p/11084304.html