admin管理员组文章数量:1416322
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;"
intr
? – 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
2 Answers
Reset to default 3You 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);
本文标签: javaselenium webdriver to get visible row number in tableStack Overflow
版权声明:本文标题:java - selenium webdriver to get visible row number in table - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745250391a2649789.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论