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()
  • 相关阅读:
    Sitecore 9 介绍
    Sitecore个性化
    Sitecore个性化
    Sitecore A / B测试
    Sitecore性化
    cesium结合geoserver利用WFS服务实现图层编辑(附源码下载)
    leaflet地图全图以及框选截图导出功能(附源码下载)
    openlayers6结合geoserver利用WFS服务实现图层编辑功能(附源码下载)
    arcgis api 4.x for js扩展MapImageLayer支持图片图层加载
    cesium结合geoserver利用WFS服务实现图层删除(附源码下载)
  • 原文地址:https://www.cnblogs.com/qingqing-919/p/8708540.html
Copyright © 2011-2022 走看看