zoukankan      html  css  js  c++  java
  • Selenium WebDriver-下拉框断言

    #encoding=utf-8
    import unittest
    import time
    import chardet
    from selenium import webdriver
     
    class VisitSogouByIE(unittest.TestCase):
    
        def setUp(self):
            #启动IE浏览器
            #self.driver = webdriver.Firefox(executable_path = "e:\geckodriver")
            self.driver = webdriver.Ie(executable_path = "e:\IEDriverServer")
            
        def test_checkSelectText(self):
            url = "http://127.0.0.1/test_select.html"
            # 访问自定义的html网页
            self.driver.get(url)
            # 导入Select模块
            from selenium.webdriver.support.ui import Select
            # 使用xpath定位方式获取select页面元素对象
            select_element = Select(self.driver.find_element_by_xpath("//select"))
            # 获取所有选择项的页面元素对象
            actual_options = select_element.options
            # 声明一个list对象,存储下拉列表中所期望出现的文字内容
            expect_optionsList = [u"桃子",u"西瓜",u"橘子",u"猕猴桃",u"山楂",u"荔枝"]
            # 使用Python内置map()函数获取页面中下拉列表展示的选项内容组成的列表对象
            actual_optionsList = map(lambda option: option.text, actual_options)
            # 断言期望列表对象和实际列表对象是否完全一致
            self.assertListEqual(expect_optionsList, actual_optionsList)
    
    
    
        def tearDown(self):
            # 退出IE浏览器
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()
  • 相关阅读:
    无法上网排查解决方案
    远程连接虚拟机失败解决方案
    xshell5 优化方案
    centos6.9系统优化
    阿里云slb+https 实践操作练习
    cobbler 无人值守系统安装
    分治法——大整数相乘
    杭电1006
    使用KNN对iris数据集进行分类——python
    python 当pip不能用的时候可以去找python安装包
  • 原文地址:https://www.cnblogs.com/qingqing-919/p/8709308.html
Copyright © 2011-2022 走看看