Table row count is always returned as 0

72 views
Skip to first unread message

Gursharan Singh

unread,
Jul 20, 2010, 8:08:58 AM7/20/10
to seleniu...@googlegroups.com
Hi All
I wish to get row count of a table.

Its xpath is :
/html/body/form[@id='Form1']/table/tbody/tr[5]/td/table[@id='dgAdminGroups']/tbody/tr

I am using the syntax as:

int rowCount = SetupClass.oDefaultSelenium.getXpathCount("//html/body/form[@id='Form1']/table/tbody/tr[5]/td/table[@id='dgAdminGroups']/tbody/tr").intValue();
System.out.println(rowCount);

But is always returing the value as 0.

Regards
G

Krishna chaitanya

unread,
Jul 20, 2010, 9:47:06 AM7/20/10
to seleniu...@googlegroups.com
Hi ,

getXpathCount("//table[@id='dgAdminGroups'/tbody/tr").intValue();

System.out.println(rowCount);

should be enough to get the row count of the table .

If it is not working , paste the html of the table here



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


preethi samuel

unread,
Jul 20, 2010, 10:09:45 AM7/20/10
to seleniu...@googlegroups.com
Do thread.sleep(1000) before doing row count.This might work


 
On Tue, Jul 20, 2010 at 10:08 AM, Gursharan Singh <singh.g...@gmail.com> wrote:
Thanks for ur reply: But Result is zero only :(



On 7/20/10, Krishna chaitanya <ckrishna...@gmail.com> wrote:
> Hi ,
>
> getXpathCount("//table[@id='dgAdminGroups'/tbody/tr").intValue();
>
> System.out.println(rowCount);
>
> should be enough to get the row count of the table .
>
>
>
>
> On Tue, Jul 20, 2010 at 5:38 PM, Gursharan Singh
> <singh.g...@gmail.com>wrote:
>
>> Hi All
>> I wish to get row count of a table.
>>
>> Its xpath is :
>>
>> /html/body/form[@id='Form1']/table/tbody/tr[5]/td/table[@id='dgAdminGroups']/tbody/tr
>>
>> I am using the syntax as:
>>
>> int rowCount =
>> SetupClass.oDefaultSelenium.getXpathCount("//html/body/form[@id='Form1']/table/tbody/tr[5]/td/table[@id='dgAdminGroups']/tbody/tr").intValue();
>>                        System.out.println(rowCount);
>>
>> But is always returing the value as 0.
>>
>> Regards
>> G
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Selenium Users" group.
>> To post to this group, send email to seleniu...@googlegroups.com.
>> To unsubscribe from this group, send email to

Brian Rock

unread,
Jul 20, 2010, 10:10:14 AM7/20/10
to seleniu...@googlegroups.com
What is the value that you are getting in FireBugs XPath evaluator for this? --> //html/body/
form[@id='Form1']/table/tbody/tr[5]/td/table[@id='dgAdminGroups']/tbody/tr


On Tue, Jul 20, 2010 at 9:08 AM, Gursharan Singh <singh.g...@gmail.com> wrote:
Thanks for ur reply: But Result is zero only :(


On 7/20/10, Krishna chaitanya <ckrishna...@gmail.com> wrote:
> Hi ,
>
> getXpathCount("//table[@id='dgAdminGroups'/tbody/tr").intValue();
>
> System.out.println(rowCount);
>
> should be enough to get the row count of the table .
>
>
>
>
> On Tue, Jul 20, 2010 at 5:38 PM, Gursharan Singh
> <singh.g...@gmail.com>wrote:
>
>> Hi All
>> I wish to get row count of a table.
>>
>> Its xpath is :
>>
>> /html/body/form[@id='Form1']/table/tbody/tr[5]/td/table[@id='dgAdminGroups']/tbody/tr
>>
>> I am using the syntax as:
>>
>> int rowCount =
>> SetupClass.oDefaultSelenium.getXpathCount("//html/body/form[@id='Form1']/table/tbody/tr[5]/td/table[@id='dgAdminGroups']/tbody/tr").intValue();
>>                        System.out.println(rowCount);
>>
>> But is always returing the value as 0.
>>
>> Regards
>> G
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Selenium Users" group.
>> To post to this group, send email to seleniu...@googlegroups.com.
>> To unsubscribe from this group, send email to

Gursharan Singh

unread,
Jul 20, 2010, 10:14:27 AM7/20/10
to seleniu...@googlegroups.com
I ALREADY TRIED SETTING SLEEP AS 5000 BUT NO SUCESS

>> <selenium-users%2Bunsu...@googlegroups.com<selenium-users%252Buns...@googlegroups.com>

preethi samuel

unread,
Jul 20, 2010, 10:16:57 AM7/20/10
to seleniu...@googlegroups.com
When you evaluate this  in xpather are you getting any rows?

Gursharan Singh

unread,
Jul 20, 2010, 10:19:09 AM7/20/10
to seleniu...@googlegroups.com
yes i m getting all the rows when i use the following in xpathchecker

i.e. /html/body/form[@id='Form1']/table/tbody/tr[5]/td/table[@id='dgAdminGroups']/tbody/tr

>> >> <selenium-users%2Bunsu...@googlegroups.com<selenium-users%252Buns...@googlegroups.com>
>> <selenium-users%252Buns...@googlegroups.com<selenium-users%25252Bun...@googlegroups.com>

Gursharan Singh

unread,
Jul 20, 2010, 10:23:41 AM7/20/10
to seleniu...@googlegroups.com
from firebugs it comes out the there is a table with in a table i.e.
second table is contained in one of the row of parent table

>> <selenium-users%2Bunsu...@googlegroups.com<selenium-users%252Buns...@googlegroups.com>

Gursharan Singh

unread,
Jul 21, 2010, 12:44:30 AM7/21/10
to seleniu...@googlegroups.com
Brian,
NO DATA seems unquie. HTML structure is something like this: I have
also attached the screenshot of html from firebug.
<table>
<tbody>
<tr>
<tr>
<tr>
<tr>
<td>
<table>
<tbody>
<tr>
<tr>
<tr>
<tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>

On 7/20/10, Brian Rock <bria...@gmail.com> wrote:

> So are you saying that in Firebug you are getting multiple matches for your
> xpath string? i.e. is your xpath unique enough to return unambiguous
> results?
>
> Brian
>
>
> On Tue, Jul 20, 2010 at 9:23 AM, Gursharan Singh

>> >> <selenium-users%2Bunsu...@googlegroups.com<selenium-users%252Buns...@googlegroups.com>
>> <selenium-users%252Buns...@googlegroups.com<selenium-users%25252Bun...@googlegroups.com>

table.png

Brian Rock

unread,
Jul 21, 2010, 8:47:57 AM7/21/10
to seleniu...@googlegroups.com
Since you're listing the ID in the xpath (/html/body/form[@id='Form1']/
table/tbody/tr[5]/td/table[@id='dgAdminGroups']/tbody/tr) it seems like your firebug should return a count of 5.  If this is the case and your script is returning zero, it may be that the call to GetXpathCount is firing before the page is fully rendered.  I would try, for a test, to put in a large sleep statement (Thread.Sleep(15000); in C#) right before the call to see if it returns the correct count.  There are a number of scripts where I have had to put in small sleeps to avoid this problem, usually 2.5 second (2500ms) does the trick.

Thanks
Brian

Gursharan Singh

unread,
Jul 21, 2010, 9:01:09 AM7/21/10
to seleniu...@googlegroups.com
Thanks Brian, i tried with sleep as 15000 but no sucess. I am even
checking if element is present or not before getting xpathcount. It is
returing me true for that but not giving proper value when getting its
row count

boolean x = SetupClass.oDefaultSelenium.isElementPresent("xpath=//html/body/form[@id='Form1']/table/tbody/tr[5]/td/table[@id='dgAdminGroups']/tbody/tr");
System.out.println(x);


int rowCount =
SetupClass.oDefaultSelenium.getXpathCount("//html/body/form[@id='Form1']/table/tbody/tr[5]/td/table[@id='dgAdminGroups']/tbody/tr").intValue();

System.out.println(rowCount);

>> >> >> <selenium-users%2Bunsu...@googlegroups.com<selenium-users%252Buns...@googlegroups.com>
>> <selenium-users%252Buns...@googlegroups.com<selenium-users%25252Bun...@googlegroups.com>
>> >
>> >> <selenium-users%252Buns...@googlegroups.com<selenium-users%25252Bun...@googlegroups.com>
>> <selenium-users%25252Bun...@googlegroups.com<selenium-users%2525252Bu...@googlegroups.com>

Brian Rock

unread,
Jul 21, 2010, 9:10:41 AM7/21/10
to seleniu...@googlegroups.com
What is you try this

//*table[contains(@id,'dgAdminGroups')]/tbody/tr

Gursharan Singh

unread,
Jul 21, 2010, 9:24:25 AM7/21/10
to seleniu...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages