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() |
现在我也找了很多测试的朋友,做了一个分享技术的交流群,共享了很多我们收集的技术文档和视频教程。
如果你不想再体验自学时找不到资源,没人解答问题,坚持几天便放弃的感受
qq群号:485187702【暗号:csdn11】
可以加入我们一起交流。而且还有很多在自动化,性能,安全,测试开发等等方面有一定建树的技术大牛
分享他们的经验,还会分享很多直播讲座和技术沙龙
可以免费学习!划重点!开源的!!!
视频+文档+PDF+面试题可以关注公众号:【软件测试小dao】
最后感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走! 希望能帮助到你!【100%无套路免费领取】