简体   繁体   English

如何使用ruby水豚从表中获取行数?

[英]How to get row count from a table using ruby capybara?

In Java, we use: 在Java中,我们使用:

WebElement tablename=driver.findElement(By.xpath("table_xpath"));

WebElement<List> rowcount=tablename.findelements(By.tagname("tr"));

sys(rowcount.size());

How to find row count in Ruby Capybara for above case? 对于上述情况,如何在Ruby Capybara中查找行数?

You can find all the elements matching a selector using #all so 您可以使用#all找到与选择器匹配的所有元素

page.all(:css, 'table tr').size

will count all the table rows in the page. 将计算页面中的所有表行。 If there are multiple tables and you want for a specific table you can increase the specificity of the CSS selector. 如果有多个表,并且想要一个特定的表,则可以增加CSS选择器的特异性。 You can also find the specific table and then call all on that 您还可以找到特定的表格,然后在该表格上调用all表格

table = page.find(:css, 'table#my_table_id')
row_count = table.all(:css, 'tr').size

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM