Selenium WebDriver-下拉框断言

本文介绍如何使用Selenium和Python进行网页元素的选择测试,通过IE浏览器访问自定义HTML页面,并验证下拉列表的内容。
#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()

 

转载于:https://www.cnblogs.com/qingqing-919/p/8709308.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值