java - How to access a specific row from web table -


i'm trying select specific row having class name 'topicrow post' table given below

code on website

<table class="content" width="100%"> <tbody>     <tr class="topictitle">     <tr class="topicsubtitle">     <tr class="topicrow post">     <tr class="topicrow_alt post_alt">     <tr class="topicrow post">     <tr class="topicrow_alt post_alt">     <tr id="forum_ctl03_ctl00" class="header2">     <tr class="post">     <tr> </tbody> </table> 

selenium code

webelement webtable=driver.findelement(by.xpath("//*[@class='content']")); list<webelement> totalrowcount=webtable.findelements(by.xpath("//*[@class='content']/tbody/tr[contains(@class,'topicrow post')]")); system.out.println("no. of rows in webtable: "+totalrowcount.size()); 

problem

every time prints size of rows present in table. please guide...

in code, had use webtable find rows, still repeat xpath portion "//*[@class='content']" webtable in webtable.findelements().

change code below:

list<webelement> totalrowcount=webtable.     findelements(by.xpath(".//tr[contains(@class,'topicrow post')]")); 

or change use driver.findelements() repeated xpath portion:

list<webelement> totalrowcount=driver.      findelements(by.xpath("//*       [@class='content']/tbody/tr[contains(@class,'topicrow post')]")); 

if above 2 ways don't work expected, try below code:

webelement table = driver.findelement(by.css("table.content")); list<webelement> foundrows = table.findelements(by.css("tr.topicrow.post")); system.out.println("found rows count: "+ foundrows.size()); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -