<练手1>(python+selenium)随机生成搜索码,搜索,并在搜索栏匹配结果进行输出

字典管理模块,想进行生成随机字典码,搜索,匹配结果并输出的功能
页面

html

代码

 #搜索功能
        number1=random.randint(0,20) #生成整数随机字典码
        number="%02d"%number1 #如果是个位数,十位自动补0
        print(u"搜索的随机数为:"number)
        driver.find_element_by_id("SearchKey").send_keys(number)
        driver.find_element_by_id("btnSearch").click()

#下拉框选择
        sel=driver.find_element_by_id("s_typeId")
        Select(sel).select_by_value("2")           
        lists=driver.find_element_by_id("list").find_elements_by_xpath("//tbody/tr[@tabindex='-1']/td[@aria-describedby='list_GbCode']")
        lists2=driver.find_element_by_id("list").find_elements_by_xpath("//tbody/tr[@tabindex='-1']/td[@aria-describedby='list_TypeName']
        print(u"搜索结果条数:",len(lists))
        if len(lists)!=0:
#精确查询           
            for list in lists:
                if list.get_attribute('title') !=str(number):
                    print(u"搜索结果不正确")
                    print(list.get_attribute('title'))
                else:
                    print(u"搜索结果正确")
#精确查询

#模糊查询
             for list in lists:
                if str(number) in list.get_attribute('title'):
                    for list2 in  lists2:
                        print(u"搜索字典码结果正确")
                        if list2.get_attribute('title')!="政治面貌代码":
                            print(u"字典类型不匹配",list2.get_attribute('title'))
                        else:
                            print(u"搜索字典类型结果正确")
                else:
                    print(u"字典代码不正确,此项字典代码为:",list.get_attribute('title'))
#模糊查询    
        else:
            print(u"搜索结果为空")
        print(u"字典管理:搜索功能测试完毕")

总结:
写得乱七八糟了,希望后期没有那么辣鸡的时候知道如何修改

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值