使用selenium+python操作table的查询结果

判定输入的查询条件正确的匹配查询结果,项目使用的是模糊查询,且查询结果以列表的方式显示出来,简单的编写如下函数:

def test_searchUser(self):  #定义一个查询方法
        self.logclass.logIn(self.URL,self.username,self.userpass)   #调用logclass模块的登录功能
        driver=self.driver


        #Enter  authority management
        driver.find_element_by_css_selector("li.img-five").click()
        driver.implicitly_wait(10)


        #Enter User management
        driver.find_element_by_css_selector("p.item.sub").click()
        driver.implicitly_wait(15)

        #输入查询条件进行查询
        driver.find_element_by_id("searchname").send_keys("oo")
        driver.find_element_by_id("searchtruename").send_keys("di")
        


        #Click search button
        driver.find_element_by_id("search").click()
        driver.implicitly_wait(15)
        

        #driver.refresh()

        #获取查询后table的行数以及列数

        table=driver.find_element_by_id("dataTables-example")
        table_rows=table.find_elements_by_tag_name("tr") #get total row number    
        table_cols=table.find_elements_by_tag_name("th") #get table's colums


        print "Total Rows:",len(table_rows)
        print "Total Colunms:",len(table_cols)

        使用assertTrue()对table中每个查询结果做判断
        #print table_rows[1].find_elements_by_tag_name('td')[1].text
        if len(table_rows)>=1:
            table_num=1
            for table_num in range(1,len(table_rows)):
                table_text=table_rows[table_num].find_elements_by_tag_name('td')[1].text
                print table_text
                self.assertTrue("oo" in table_text) #the contents that be found in table_text
        else:
            print "There is not record!!"
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值