java - selenium webdriver to get visible row number in table - Stack Overflow

I am writing test script using selenium webdriver and java for page which has a table with multiple row

I am writing test script using selenium webdriver and java for page which has a table with multiple rows column. This rows has same style and class. However, some of rows are hidden and some of them are displayed on page. There are ~1800 rows from which only seven rows are displayed on page. Now, I have to work on visible row for process data, I have created xpath but it is taking very long time to verify which row number is visible on page and if visible than proceed further with running script else check next row. This I have achieved by using for loop but it is too time consuming. Well there is a drop down option in rows but the id of those drop down is dynamic based on table row like testid_0 - row 1, testid_1 - row 2. My question is there any way we can get the visible row number of table like row 7, row 100, row 500 which is visible on page without spending time or using for loop? or can we get the javascript which run using selenium and return the number of row which are displayed on page.

I am writing test script using selenium webdriver and java for page which has a table with multiple rows column. This rows has same style and class. However, some of rows are hidden and some of them are displayed on page. There are ~1800 rows from which only seven rows are displayed on page. Now, I have to work on visible row for process data, I have created xpath but it is taking very long time to verify which row number is visible on page and if visible than proceed further with running script else check next row. This I have achieved by using for loop but it is too time consuming. Well there is a drop down option in rows but the id of those drop down is dynamic based on table row like testid_0 - row 1, testid_1 - row 2. My question is there any way we can get the visible row number of table like row 7, row 100, row 500 which is visible on page without spending time or using for loop? or can we get the javascript which run using selenium and return the number of row which are displayed on page.

Share Improve this question edited Jul 26, 2015 at 8:48 nathanchere 8,09815 gold badges68 silver badges86 bronze badges asked Dec 21, 2014 at 11:07 Karim NarsindaniKarim Narsindani 4544 gold badges14 silver badges39 bronze badges 2
  • How rows are hidden? Using style="display:none;" in tr? – Ruslan Ostafiichuk Commented Dec 21, 2014 at 11:59
  • Yes Ruslan, it has same style as you mention (class="row" style="display: none;") in tr – Karim Narsindani Commented Dec 21, 2014 at 12:06
Add a ment  | 

2 Answers 2

Reset to default 3

You can filter invisible tr using proper xpath, like:

//table/tbody/tr[not(contains(@style,'display: none;'))]

You can also try the below code to get the count of rows that are visible(Assuming there is just one table in the webpage):

int count = 0;
List<WebElement> rows = driver.findElements(By.xpath("//table//tr"));
for(WebElement row: rows){
  if(row.isDisplayed())
    count++;
}
System.out.println("The number of rows that are visible is: "+ count);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745250392a4618644.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信