How to find the number of rows in a Table using Selenium IDE?

3,003 views
Skip to first unread message

mr. twistyneck

unread,
Sep 8, 2013, 11:17:22 AM9/8/13
to seleniu...@googlegroups.com
First time poster -

I'm using Selenium IDE to cycle through a table and check a box in a certain Cell.  The cell's locator is a combination of text found in the first cell of the row, combined with some static text. So what I initially did was this:

Table name:  TblConstruct

storeTable | TblConstruct.3.0 | label  this finds the text stored in row 3, column 0 and stores it in variable 'label'
click | name_${label}  Each row has a checkbox at the end of the row, whose locator is 'name_' plus the text stored in 'label'

What I'm running into is that I don't know the total number of rows in the table - and when I cycle through the rows using the GotoIf extension for looping - i run past the end of my table.  My table has 1 to X number of rows - it differs on each page. 
  • First, I tried locating a command that would tell me if the checkbox was there - but StoreElementPresent doesn't work with "TblConstruct.57.0" as a Target (for example).  I can't use the actual locator, because part of the locator is in the first column - but if the row doesn't exist, I have no locator to compare. 
  • Next, I tried StoreXpathCount - and got nowhere.  I tried StoreXpathCount | //table[@id='TblConstruct']/tbody/tr | rows - but when I went to echo ${rows}, i got zero '0'
Lastly, I fiddled around with assertTable.  My test table has 26 rows, so I threw the following command at it - essentially "go assert something that doesn't exist" - like go find row 60, which isn't there.

[info] Executing | assertTable | TblConstruct.60.0
[error] Cannot access row 60 - table has 26 rows

and here's what's confusing - I can't figure out how to return the number or rows in the table - but Selenium IDE's error message spit it out just fine - it knows there are 26 rows - and I didn't supply an Xpath.  How can I proactively get that row count?
Thanks!
Twisty

alainam...@gmail.com

unread,
Aug 21, 2015, 3:57:17 AM8/21/15
to Selenium Users

     Searching exactly for the same problem. I have also tried storeXpathCount and storeElementIndex but got nothing.

Sonia saini

unread,
Aug 21, 2015, 6:27:40 AM8/21/15
to seleniu...@googlegroups.com
Can you please provide your DOM/HTML code?

On Fri, Aug 21, 2015 at 12:07 PM, <alainam...@gmail.com> wrote:

     Searching exactly for the same problem. I have also tried storeXpathCount and storeElementIndex but got nothing.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/6167ab03-12f2-419a-b028-98c85e820d6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Sonia saini

alainam...@gmail.com

unread,
Aug 25, 2015, 6:33:56 AM8/25/15
to Selenium Users
My html code:
<table id="emailsSentTable" class="table table-bordered dataTable no-footer" role="grid" style="background-color: rgb(204, 204, 204);">
                    <thead>
                        <tr role="row"><th class="th-one sorting_asc" tabindex="0" aria-controls="emailsSentTable" rowspan="1" colspan="1" style="width: 252px; background-color: transparent;" aria-label="
                                Name

                            : activate to sort column descending" aria-sort="ascending">
                                Name

                            </th><th class="th-two sorting" tabindex="0" aria-controls="emailsSentTable" rowspan="1" colspan="1" style="width: 359px;" aria-label="
                                Email

                            : activate to sort column ascending">
                                Email

                            </th><th class="th-three sorting" tabindex="0" aria-controls="emailsSentTable" rowspan="1" colspan="1" style="width: 85px;" aria-label="
                                Status
                            : activate to sort column ascending">
                                Status
                            </th></tr>
                    </thead>
                    <tbody style="background-color: transparent;">
                           
                           
                           
                           
                           

                    <tr role="row" class="odd" style="background-color: rgb(255, 255, 255);">
                                <td class="th-one sorting_1" style="background-color: transparent;">
                                    alaina
                                </td>
                                <td class="th-two" style="background-color: transparent;">
                                    alain...@hotmail.com
                                </td>
                                <td class="th-three">
                                    Unopened
                                </td>
                            </tr><tr role="row" class="even" style="background-color: rgb(255, 255, 255);">
                                <td class="th-one sorting_1">
                                    Aleena
                                </td>
                                <td class="th-two">
                                    aleenam...@gmail.com
                                </td>
                                <td class="th-three">
                                    Unopened
                                </td>
                            </tr><tr role="row" class="odd">
                                <td class="th-one sorting_1">
                                    mubashar
                                </td>
                                <td class="th-two">
                                    imubas...@gmail.com
                                </td>
                                <td class="th-three">
                                    Unopened
                                </td>
                            </tr><tr role="row" class="even">
                                <td class="th-one sorting_1">
                                    nadeem
                                </td>
                                <td class="th-two">
                                  
                                </td>
                                <td class="th-three">
                                    Unopened
                                </td>
                            </tr><tr role="row" class="odd">
                                <td class="th-one sorting_1">
                                    tester
                                </td>
                                <td class="th-two">
                                    tester...@gmail.com
                                </td>
                                <td class="th-three">
                                    Unopened
                                </td>
                            </tr></tbody>
                </table>

Kaleem Uddin Mohammed Abdul

unread,
Aug 25, 2015, 7:29:54 AM8/25/15
to Selenium Users

List<WebElement> Rows=_WebDriver.findElements(By.xpath("//table[@id='emailsSentTable']/tbody/tr"))
Rows.size() gives you total rows in Java, provided their is only on table with emailsSentTable id.

alainam...@gmail.com

unread,
Aug 26, 2015, 3:23:31 AM8/26/15
to Selenium Users
Thanks for the help but i am looking for a solution in selenium IDE.

Kaleem Uddin Mohammed Abdul

unread,
Aug 26, 2015, 3:34:51 AM8/26/15
to Selenium Users
count(//table[@id='emailsSentTable']/tbody/tr)


On Sunday, September 8, 2013 at 8:47:22 PM UTC+5:30, mr. twistyneck wrote:

Nick Smith

unread,
Aug 26, 2015, 4:16:12 AM8/26/15
to Selenium Users
Hey,

Unless I'm totally missing your point here, aren't you just using the wrong table ID in your xpath?

In your first post you have it as 'TblConstruct' but in your DOM it has an ID of 'emailsSentTable'.

Using the storeXpathCount command on your example HTML/DOM with target of "//table[@id='emailsSentTable']/tbody/tr" brings back 5 rows, that's exactly what you need right?

alainam...@gmail.com

unread,
Aug 26, 2015, 5:19:48 AM8/26/15
to Selenium Users
Yes, that's exactly i need but i have tried exactly the way you mentioned i.e Command: storeXpathCount Target://table[@id='emailsSentTable']/tbody/tr'' but it is returning 10.

Nick Smith

unread,
Aug 26, 2015, 6:21:02 AM8/26/15
to Selenium Users
OK, then it seems you're either not giving us the full DOM/HTML or you're running your command against a different structure?

I can't see any other reason why you'd be getting different counts, if it returns 10 table rows for you, then there are 10 <TR> elements in your HTML, but only 5 in the example you gave us here.

How many rows do you get when you run it purely against the HTML you gave us above?

Are you giving us the full HTML you're using?

alainam...@gmail.com

unread,
Aug 28, 2015, 5:01:30 AM8/28/15
to Selenium Users
O yess! you are right as i was not proving you with my complete HTML.....Thanks a lot for the help :)

Nick Smith

unread,
Aug 28, 2015, 5:24:00 AM8/28/15
to Selenium Users
Very welcome.
Reply all
Reply to author
Forward
0 new messages