zoukankan      html  css  js  c++  java
  • Selenium WebDriver的多浏览器测试

    1. IE浏览器,需要配合下载IEDriverSever.exe的驱动程序,目前selenium支持IE9以上。

    (驱动程序下载链接:https://pan.baidu.com/s/1YpaUsIs128znSOBQmHdzWw 密码: mxfq)。

    访问搜狗主页的脚本:

    #VisitSogouByIE.py 访问搜狗主页例子
    
    #encoding=utf-8
    from selenium import webdriver
    import unittest
    
    class VisitSogouByIE(unittest.TestCase):
    
        def setUp(self):
            # 启动IE浏览器
            self.driver = webdriver.Ie(executable_path = "e:\IEDriverServer")
    
        def test_visitSogou(self):
            # 访问搜索首页
            self.driver.get("http://www.sogou.com")
            # 打印当前网页的网址
            print self.driver.current_url
    
        def tearDown(self):
            # 退出IE浏览器
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()

    #encoding=utf-8
    from selenium import webdriver
    import unittest

    class VisitSogouByIE(unittest.TestCase):

    def setUp(self):
    # 启动IE浏览器
    self.driver = webdriver.Ie(executable_path = "e:\IEDriverServer")

    def test_visitSogou(self):
    # 访问搜索首页
    self.driver.get("http://www.sogou.com")
    # 打印当前网页的网址
    print self.driver.current_url

    def tearDown(self):
    # 退出IE浏览器
    self.driver.quit()

    if __name__ == '__main__':
    unittest.main()

    2. Firefox浏览器,需要配合下载geckoDriver.exe的驱动程序

    (驱动程序下载地址:https://pan.baidu.com/s/16X-dRmSzrUx-r1rIaCnQFw 密码: ra79)

    访问搜狗主页的脚本:

    #encoding=utf-8
    from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
    from selenium import webdriver
    import unittest
    
    class VisitSogouByFirefox(unittest.TestCase):
    
        def setUp(self):
            #binary = FirefoxBinary('D:\FirefoxPortable\Firefox.exe')
            # 启动Firefox浏览器
            self.driver = webdriver.Firefox(executable_path = "e:\geckodriver")
            #driver = webdriver.Firefox(firefox_binary = binary,executable_path = r"c:geckodriver")
        def test_visitSogou(self):
            # 访问搜索首页
            self.driver.get("http://www.sogou.com")
            # 打印当前网页的网址
            print self.driver.current_url
    
        def tearDown(self):
            # 退出firefox浏览器
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()

    3. Firefox浏览器,需要配合下载 chromedriver.exe的驱动程序

    (驱动程序下载地址:https://pan.baidu.com/s/1Sei0ZkcjNYBsdNUKPEgKYg 密码: br6s)

    访问搜狗主页的脚本:

    #encoding=utf-8
    from selenium import webdriver
    import unittest
    
    class VisitSogouByChrome(unittest.TestCase):
    
        def setUp(self):
            # 启动Chrome浏览器
            self.driver = webdriver.Chrome(executable_path = "E:\chromedriver")
    
        def test_visitSogou(self):
            # 访问搜索首页
            self.driver.get("http://www.sogou.com")
            # 打印当前网页的网址
            print self.driver.current_url
    
        def tearDown(self):
            # 退出IE浏览器
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()
  • 相关阅读:
    P5136 sequence(矩阵快速幂)
    P5135 painting(组合数)
    CF888E Maximum Subsequence(meet in the middle)
    P4463 [国家集训队] calc(拉格朗日插值)
    CF364D Ghd(随机化)
    P3270 [JLOI2016]成绩比较(拉格朗日插值)
    bzoj3453: tyvj 1858 XLkxc(拉格朗日插值)
    P4593 [TJOI2018]教科书般的亵渎(拉格朗日插值)
    tomcat8版本实现虚拟主机
    NFS网络文件系统方案
  • 原文地址:https://www.cnblogs.com/qingqing-919/p/8708540.html
Copyright © 2011-2022 走看看