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()
  • 相关阅读:
    linux创建用户与删除用户及问题解决(ubuntu)
    Build tool
    Version Control&Git
    IntelliJ IDEA激活
    KDJ 指标
    MACD 分析理解
    MACD 指标
    BOLL 指标
    IaaS,PaaS,SaaS 的区别
    Kubernetes 第十七章 调度器 污点和容忍 以及高级调度方式
  • 原文地址:https://www.cnblogs.com/qingqing-919/p/8708540.html
Copyright © 2011-2022 走看看