How to Click an Image by onclick attribute?

901 views
Skip to first unread message

Rodrigo Martín

unread,
Sep 28, 2010, 11:24:01 AM9/28/10
to robotframework-users
Hello everyone!
I need to click a "Delete" image in a table, which doesn't have an ID
that ties the image with the item to be deleted.
However, the "onclick" contains the Name of the Item to delete, so I
thought using that for proper automation. How can I identify an image
by using this "onclick" attribute?

Here is the HTML object mentioned:

<img border="1" src="/images/delete.gif" onclick="if
(confirmDelete( 'RinaTest' ) ) window.location='DeletePromotion.do?
metadata_id=130'" title="Delete">

Any help will be really appreciated!
Thanks and Regards,

Rodrigo.

Janne Härkönen

unread,
Sep 29, 2010, 2:35:14 AM9/29/10
to adi...@gmail.com, robotframework-users
On Tue, Sep 28, 2010 at 6:24 PM, Rodrigo Martín <adi...@gmail.com> wrote:
> Hello everyone!
> I need to click a "Delete" image in a table, which doesn't have an ID
> that ties the image with the item to be deleted.
> However, the "onclick" contains the Name of the Item to delete, so I
> thought using that for proper automation. How can I identify an image
> by using this "onclick" attribute?
>
> Here is the HTML object mentioned:
>
> <img border="1" src="/images/delete.gif" onclick="if
> (confirmDelete( 'RinaTest' ) ) window.location='DeletePromotion.do?
> metadata_id=130'" title="Delete">

Hello Rodrigo,

If I parsed the HMTL correctly, you should be able to find the image
using an XPath expression like this:

Click Element xpath=//img[@src="/images/delete.gif" and @onclick="if
(confirmDelete( 'RinaTest' ) )
window.location='DeletePromotion.do?metadata_id=130'"]

hth,

__janne

Rodrigo Martín

unread,
Sep 29, 2010, 7:18:38 PM9/29/10
to robotframework-users
Thanks again Janne.

So could I use something like this? Not sure if this is correctly
implemented. Suppose I do know the name of the item to be deleted, and
want to add a wildcard "*" for ignoring the last part of locator:

onclick_string = "if (confirmDelete( '${promo_name} ) )*" // This
statement will gather the promo_name I already know, and transform it
to a string.
Click Element xpath=//img[@src="/images/delete.gif" and @onclick=$
{onclick_string}]

This sounds reasonable? Will try to implement tomorrow and let u know.
Regards!
Reply all
Reply to author
Forward
0 new messages