硒黄瓜,如何计数表行

时间:2017-12-14 14:24:20

标签: ruby selenium-webdriver cucumber

我有一个分页表,我想计算这个表的所有行,这就是我做的:

   Then /^I should have (\d+) table rows$/ do |number_of_rows|
 actual_number = page.all('.table.table-striped tr').size
 actual_number.should == number_of_rows
end

但是我收到了这个错误:

undefined method `page' for #<Selenium::WebDriver::Chrome::Driver:0xb628dc20 browser=:chrome> (NoMethodError)

谢谢,

1 个答案:

答案 0 :(得分:1)

正如您所看到的,您的块在Web驱动程序实例的上下文中进行了评估。 WebDriver没有页面方法,但它有查找元素的方法。这对你有什么用?

Then /^I should have (\d+) table rows$/ do |number_of_rows|
  actual_number = $driver.find_elements({css:'.table.table-striped tr'}).size
  actual_number.should == number_of_rows
end