这篇文章主要为大家介绍了python自动化测试selenium定位frame及iframe示例的示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助
frame标签有frameset、frame、iframe三种,frameset和其它普通标签没有区别,不会影响正常定位,而frame与iframe对selenium定位而言是一样的。
Selenium有以下方法对frame进行操作。
示例网站:http://sahitest.com/demo/framesTest.htm
示例脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | from selenium import webdriver from time import sleep class TestFrame( object ): def setup( self ): self .driver = webdriver.Chrome() self .driver.get( "http://sahitest.com/demo/framesTest.htm" ) def test_frame( self ): top = self .driver.find_element_by_name( "top" ) # 切换到上面的frame self .driver.switch_to.frame(top) #点击上面frame中的Link Test链接,打开新页面 self .driver.find_element_by_xpath( "/html/body/table/tbody/tr/td[1]/a[1]" ).click() #切换到主页面 self .driver.switch_to.default_content() sleep( 3 ) # 切换到下面的frame second = self .driver.find_element_by_xpath( "/html/frameset/frame[2]" ) self .driver.switch_to.frame(second) # 点击下面frame中的Form Test链接,打开新页面 self .driver.find_element_by_xpath( "/html/body/table/tbody/tr/td[1]/a[2]" ).click() sleep( 2 ) self .driver.quit() if __name__ = = '__main__' : frame = TestFrame() frame.test_frame() |
以上来自:极客时间课程:selenium自动化测试课程学习总结。
以上就是python自动化测试selenium定位frame及iframe示例的详细内容
下面是配套资料,对于做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!
软件测试面试小程序
被百万人刷爆的软件测试题库!!!谁用谁知道!!!全网最全面试刷题小程序,手机就可以刷题,地铁上公交上,卷起来!
涵盖以下这些面试题板块:
1、软件测试基础理论 ,2、web,app,接口功能测试 ,3、网络 ,4、数据库 ,5、linux
6、web,app,接口自动化 ,7、性能测试 ,8、编程基础,9、hr面试题 ,10、开放性测试题,11、安全测试,12、计算机基础
资料获取方式 :