欢迎光临
我们一直在努力

python自动化测试selenium定位frame及iframe的示例分析

小编给大家分享一下python自动化测试selenium定位frame及iframe的示例分析,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

frame标签有frameset、frame、iframe三种,frameset和其它普通标签没有区别,不会影响正常定位,而frame与iframe对selenium定位而言是一样的。

Selenium有以下方法对frame进行操作。

示例网站:http://sahitest.com/demo/framesTest.htm

示例脚本:

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()

看完了这篇文章,相信你对“python自动化测试selenium定位frame及iframe的示例分析”有了一定的了解,如果想了解更多相关知识,欢迎关注云搜网行业资讯频道,感谢各位的阅读!

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。