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