首页 > 编程 > Python > 正文

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

2019-11-06 08:17:41
字体:
来源:转载
供稿:网友

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

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"字典管理:搜索功能测试完毕")

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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表