18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

SAHI selector by onclick attribute

tower120tower120 Members
edited November -1 in Sahi - Open Source
Hi!

Is there any way to get element by onclick attribute? For ex., I have:
<a href="javascript:void(0);" onclick="toggle_invoice_payment_allowed_status('16199')">
<img src="/s/icons/thumbs_down.png" title="Current Status :: No, Click to Toggle Status">
<br>No
</a>

I want to get this _link by onclick value. I can get this with css selector, in this way:
a[onclick~='toggle_invoice_payment_allowed_status']

Comments

  • Hi tower120,

    We cannot get element by using onclick attribute.

    Regards,
    Theeran
  • globalwormingglobalworming Moderators
    edited October 2011
    Hey guys

    why not? Using the sahi controller with accessor $element.onclick, it returns "null" when there's no onclick defined... and if defined, it returns "function onclick(event) { / /some code }"
    so... as I see it _image("Current Status :: No, Click to Toggle Status").onclick should return "function onclick(event) { toggle_invoice_payment_allowed_status('16199')}" and you should be able to do asserts with this string...

    and if you are looking for an element, loop through the elements.onclick and compare them with your expected "toggle..."

    Regards
    Wormi
Sign In or Register to comment.