我正在使用硒和生菜在 python 中进行测试。我有这个步骤来计算员工表的行数
@step('I count employee table rows')
def i_count_emp_table_rows(step):
try:
elems = world.driver.find_elements_by_xpath(".//*[@id='myTable']/tr")
sum = 0
for item in elems:
sum= sum+1
return sum
except Exception, e:
print e
return None
我还有一步,在这一步中,我想在单击添加员工按钮后转到下一页之前保存员工表中的员工数量(使用上述步骤)。
@step('I click the Add Employee Button')
def i_click_the_add_employee_button(step):
world.prev_no_of_emp = step.given('I count employee table rows')
print "Right Now total rows in table: " + str(world.pre_no_of_emp)
done, world.driver = click_page_element(admin_add_employee_button_xpath, world.driver, wait=10)
但有趣的是,我总是得到“真”而不是列表计数。我什至使用了len()但没有成功
这是 print 语句的结果。
现在表格中的总行数:True