Watir webdriver - How to click on last <td> in table ?

1,359 views
Skip to first unread message

watir webdriver

unread,
Apr 25, 2013, 12:34:21 PM4/25/13
to watir-...@googlegroups.com
Hi there,

In my application,I've to select the last td (which is an img) in table.Can anyone help me with this ?

HTML :

<table class="rctable">
<thead>
<tbody>
<tr>
<td>
<a href="edit.page?id=6">Shirts main</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=6">
<a href="edit.page?id=6">
<a href="?duplicateId=6">
</td>
</tr>
<tr>
<td>
<a href="edit.page?id=7">Suits main</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=7">
<a href="edit.page?id=7">
<a href="?duplicateId=7">
</td>
</tr>
<tr>
<td>
<a href="edit.page?id=8">Shoes main</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=8">
<a href="edit.page?id=8">
<a href="?duplicateId=8">
</td>
</tr>
<tr>
<td>
<a href="edit.page?id=10">Womens main</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=10">
<a href="edit.page?id=10">
<a href="?duplicateId=10">
</td>
</tr>
<tr>
<td>
<a href="edit.page?id=11">Coats side</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=11">
<a href="edit.page?id=11">
<a href="?duplicateId=11">
</td>
</tr>
<tr>
<td>
<a href="edit.page?id=12">Knitwear side</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=12">
<a href="edit.page?id=12">
<a href="?duplicateId=12">
</td>
</tr>
<tr>
<td>
<a href="edit.page?id=13">New side</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=13">
<a href="edit.page?id=13">
<a href="?duplicateId=13">
</td>
</tr>
<tr>
<td>
<a href="edit.page?id=14">Shoes side</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=14">
<a href="edit.page?id=14">
<a href="?duplicateId=14">
</td>
</tr>
<tr>
<td>
<a href="edit.page?id=15">Ties side</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=15">
<a href="edit.page?id=15">
<a href="?duplicateId=15">
</td>
</tr>
<tr>
<td>
<a href="edit.page?id=16">Womens side</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=16">
<a href="edit.page?id=16">
<a href="?duplicateId=16">
</td>
</tr>
<tr>
<td>
<a href="edit.page?id=19">Home page spring</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=19">
<a href="edit.page?id=19">
<a href="?duplicateId=19">
</td>
</tr>
<tr>
<td>
<a href="edit.page?id=34">fhg</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=34">
<a href="edit.page?id=34">
<a href="?duplicateId=34">
</td>
</tr>
<tr>
<td>
<a href="edit.page?id=36">AutoTestCreative</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=36">
<a href="edit.page?id=36">
<a href="?duplicateId=36">
</td>
</tr>
<tr>
<td>
<a href="edit.page?id=37">AutoTestCreative</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=37">
<a href="edit.page?id=37">
<a href="?duplicateId=37">
</td>
</tr>
<tr>
<td>
<a href="edit.page?id=38">AutoTestCreative</a>
</td>
<td>
<a onclick="return confirm('Delete creative?')" href="delete.page?cid=38">
<a href="edit.page?id=38">
<a href="?duplicateId=38">
<img title="Duplicate" src="/tracker/images/skin2/bolean.png">
</a>
</td>
</tr>
</tbody>
</table>

Implemenetd as below :

@browser.img(:src => "/tracker/images/skin2/bolean.png").click

which is clicking on the first image.

Help is much more appreciated.

Thanks.

Željko Filipin

unread,
Apr 25, 2013, 12:36:09 PM4/25/13
to watir
On Thu, Apr 25, 2013 at 6:34 PM, watir webdriver <watirweb...@gmail.com> wrote:
@browser.img(:src => "/tracker/images/skin2/bolean.png").click
 
Try this:

@browser.imgs(:src => "/tracker/images/skin2/bolean.png").last.click

Željko
--
https://leanpub.com/watirbook

watir webdriver

unread,
Apr 30, 2013, 8:40:52 AM4/30/13
to watir-...@googlegroups.com
Thanks Filipin,

It worked.


--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.
 
watir-...@googlegroups.com
http://groups.google.com/group/watir-general
watir-genera...@googlegroups.com
 
---
You received this message because you are subscribed to a topic in the Google Groups "Watir General" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/watir-general/cGy9S3w1eNw/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to watir-genera...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

watir webdriver

unread,
Apr 30, 2013, 10:44:18 AM4/30/13
to watir-...@googlegroups.com
Sorry Filipin...ignore my previous comment...its not working and still its clicking on the first <td> in the table.

Any one can help me in this ?

Ankita@Adslot

unread,
May 9, 2013, 9:23:38 PM5/9/13
to watir-...@googlegroups.com
If the number of rows is static, would make sense to use xpath and locate the last row with it and then click on image of the last row.

something like

b.element(:xpath,"//table[@class='rctable']/tbody/tr[15]/td[2]/img[@src='/tracker/images/skin2/bolean.png']").click

Chuck van der Linden

unread,
May 15, 2013, 5:19:35 PM5/15/13
to watir-...@googlegroups.com


On Thursday, May 9, 2013 6:23:38 PM UTC-7, Ankita@Adslot wrote:
If the number of rows is static, would make sense to use xpath and locate the last row with it and then click on image of the last row.

something like

b.element(:xpath,"//table[@class='rctable']/tbody/tr[15]/td[2]/img[@src='/tracker/images/skin2/bolean.png']").click

If the number of rows/cells is predictable you don't need to resort to xpath, just  do something like

browser.table(:class => "rctable")[15][2].img.click

A few other things that might work

browser.table(:class => 'rctable').rows.last.img.click

Alex Rodionov

unread,
May 16, 2013, 7:05:17 AM5/16/13
to watir-...@googlegroups.com
Even more simple

browser.table(class: 'rctable').td(index: -1).click

watir webdriver

unread,
May 17, 2013, 11:50:00 AM5/17/13
to watir-...@googlegroups.com
Thanks experts for your help....


On Thursday, April 25, 2013 5:34:21 PM UTC+1, watir webdriver wrote:

Chuck van der Linden

unread,
May 17, 2013, 4:13:04 PM5/17/13
to watir-...@googlegroups.com
On Thursday, May 16, 2013 4:05:17 AM UTC-7, Alex Rodionov wrote:
Even more simple

browser.table(class: 'rctable').td(index: -1).click

Oh nice, did not know that trick

Although in his HTML it appears there are multiple things to click in that row, so you might need something between the TD and the .Click to better indicate what to click on .  (um, but the HTML there seems strange, unless there's ways to use the anchor tag I do not understand, because there appear to be three 'start' of anchor tags in that row, but only one close-anchor tag.. ???  meh, I'm far from an HTML expert.. still seems weird)
Reply all
Reply to author
Forward
0 new messages