How to delete specific table data from a table?

23 views
Skip to first unread message

watir webdriver

unread,
Jun 26, 2013, 7:10:44 AM6/26/13
to watir-...@googlegroups.com
Hi,

In my application I've a table with 40 rows.How do I delete some specific <td> named as "default","tags","city","organic" in  that table? All the deletes links are images with the same 
src
name.Plz find the attachment of the table row.

My step def:
Then(/^I click on all the delete rules on the setup page$/) do
words = ["default", "tags","organic","city"]
@current_page.delete_rules(:words => words)
end

In my ruby class I've added delete_rules method as below :
        def delete_rules(words)
        image_elements(:src => "/tracker/images/skin2/bin.png").click
          end
Problem here is its deleting the first row in the table..not the rows which I've mentioned in the array.

My HTML is :
<tr>
<td>
<a href="edit.page?id=83">tags</a>
</td>
<td>
<a href="delete.page?did=83">
<img title="Delete" src="/tracker/images/skin2/bin.png">
</a>
<a href="edit.page?id=83">
</td>
<td> </td>
<tr>
<td>
<a href="edit.page?id=83">default</a>
</td>
<td>
<a href="delete.page?did=83">
<img title="Delete" src="/tracker/images/skin2/bin.png">
</a>
<a href="edit.page?id=83">
</td>
<td> </td>
<tr>
<td>
<a href="edit.page?id=83">organic</a>
</td>
<td>
<a href="delete.page?did=83">
<img title="Delete" src="/tracker/images/skin2/bin.png">
</a>
<a href="edit.page?id=83">
</td>
<td> </td>
<tr>
<td>
<a href="edit.page?id=83">city</a>
</td>
<td>
<a href="delete.page?did=83">
<img title="Delete" src="/tracker/images/skin2/bin.png">
</a>
<a href="edit.page?id=83">
</td>
<td> </td>

Your help is much more appreciated.

Thanks in advance.

delete_tabledata.jpg

Joe Fleck

unread,
Jun 26, 2013, 10:48:00 AM6/26/13
to Watir General
Hi,

I think you could do this

link_href = @browser.a(:text=>'tags_rule').attribute_value("href")
link_href_arr = link_href.split("?")
@browser.a(:href=>"delete.page?#{hr_arr[hr_arr.count - 1]}")

This should work.




--
--
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 the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-genera...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

watir webdriver

unread,
Jun 26, 2013, 11:02:12 AM6/26/13
to watir-...@googlegroups.com
Thanks Joe for ur reply...but its throwing error :

Used the below code in my step defs :

link_href = @browser.a(:text=>'tags_rule').attribute_value("href")
    link_href_arr = link_href.split("?")
    @browser.a(:href=>"delete.page?#{href_arr[href_arr.count - 1]}")
Error :
      undefined local variable or method `href_arr' for #<Object:0x2a5f940> (NameError).

Thanks.

Joe Fleck

unread,
Jun 26, 2013, 11:15:14 AM6/26/13
to Watir General
Sorry,
Typo

Replace this:
@browser.a(:href=>"delete.page?#{href_arr[href_arr.count - 1]}")
with:
@browser.a(:href=>"delete.page?#{link_href_arr[link_href_arr.count - 1]}")

Joe


watir webdriver

unread,
Jun 26, 2013, 11:21:31 AM6/26/13
to watir-...@googlegroups.com
Hi Joe,

The test case is passed but it didn't delete the "tags_rule".Can you plz suggest what may the issue?


Thanks.

On Wednesday, June 26, 2013 12:10:44 PM UTC+1, watir webdriver wrote:

Joe Fleck

unread,
Jun 26, 2013, 11:47:53 AM6/26/13
to Watir General
After looking at what I sent you its missing something still.  Did you add a click method to the end of line '@browser.a(:href=>"delete.page?#{link_href_arr[link_href_arr.count - 1]}")'?  If not it won't do anything.

@browser.a(:href=>"delete.page?#{link_href_arr[link_href_arr.count - 1]}").click

Joe


watir webdriver

unread,
Jun 26, 2013, 12:01:38 PM6/26/13
to watir-...@googlegroups.com
HI Joe,

Still its not working....the href for the deletion is <a href="delete.page?did=83">
but the code which I've is looking for :href=>"delete.page?id=83"
Is there any way to to get the :href=>"delete.page?did=83"

Error :
      unable to locate element, using {:href=>"delete.page?id=83", :tag_name=>"a"} (Watir::Exception::UnknownObjectException)

Thanks in-advance.


On Wednesday, June 26, 2013 12:10:44 PM UTC+1, watir webdriver wrote:

Joe Fleck

unread,
Jun 26, 2013, 12:10:47 PM6/26/13
to Watir General
hi,

you could do this

Original:
@browser.a(:href=>"delete.page?#{link_href_arr[link_href_arr.count - 1]}").click

Modified:
@browser.a(:href=>"delete.page?d#{link_href_arr[link_href_arr.count - 1]}").click

I added a 'd' in the href element.

Your other options are to the developers make the href the same for edit and delete.  The other options is to use index.  Can be a lot of work.  Try the modified line above.

Joe



watir webdriver

unread,
Jun 26, 2013, 12:40:07 PM6/26/13
to watir-...@googlegroups.com
Thanks a lot Joe....it worked
You received this message because you are subscribed to the Google Groups "Watir General" group.

To unsubscribe from this group and stop receiving emails from it, send an email to watir-genera...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
--
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/5lWYgBrTkSo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to watir-genera...@googlegroups.com.

Joe Fleck

unread,
Jun 26, 2013, 1:09:15 PM6/26/13
to Watir General
No problem.  Grad I could help.

Joe
Reply all
Reply to author
Forward
0 new messages