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.

How to click button of an attribute value. Dont understand the syntax

keithkeith Members
edited November -1 in Sahi - Open Source
I dont understand the syntax. I think if I see these examples written for Sahi I would probably get it.


1. Click the radio button
_click(_radio(?))
With id contains "LaunchEFRadioList" and is left of the visible _label("KM StandAlone Author Home")
radio button full id name is: id=KANAAPPS_wavemakerNode_PAGE_Admin_Login_20_24__V1_K_27_K_LaunchEFRadioList_Create_btnNode;
text _label("KM StandAlone Author Home") is right of the radio button

2. Click the image button with the attribute title="Launch" below the radio button with label "KM StandAlone Author Home"
title=Launch;

3. I'm switching over from selenium where this xpath worked, what is the Sahi non-xpath syntax?
this xpath would click whatever radio button relative of the found text.
//*[contains(text(),'DefaultEF')]/preceding-sibling::*[1]
Sahi is better and will click the radio left of the found visible text. How do I do this?
Are there any examples for complex locator references?

Thanks
Keith

Comments

  • narayannarayan Administrators
    Hi Keith,

    Have you looked at
    http://sahi.co.in/w/browser-accessor-apis
    and
    http://sahi.co.in/w/sahi-api-examples
    ?

    Regards,
    Narayan
  • keithkeith Members
    The example works if you are referencing the whole id text value. So what if the three textboxes are "qazInputbox123", "wsxInputbox234", "edcInputbox345" How do I reference only the "Inputbox" part of the id string? In otherword I want to avoid refrencing the whole part of the id or not at all. Many of the elements have a type attribute where I could reference type='text'

    _textbox("q", _near(_cell("Ruby for Rails")))

    Thanks
    Keith

    Example1
    id=K_27_K_LaunchEFRadioList.EFTagId_EF_KM_AuthorHomeSA_label;
    className=KANA-CheckBox-Label KANA-RadioButton-UncheckedIcon;
    htmlFor=K_27_K_LaunchEFRadioList.EFTagId_EF_KM_AuthorHomeSA;

    Example2
    id=KANAAPPS_wavemakerNode_PAGE_Admin_Login_20_24__V1_K_27_K_LaunchEFRadioList_Create_btnNode;
    className=formLaunchButton_normal wm_Border_BottomNone wm_Border_TopNone wm_Border_LeftNone
    title=Launch;
  • narayannarayan Administrators
    You can use a regular expression of the id, or use an index as specified in
    http://sahi.co.in/w/browser-accessor-apis


    Eg.
    1)
    _radio("/LaunchEFRadioList_Create/")
    or
    _radio(0, _near(_label("KM StandAlone Author Home")))
    or
    _radio("/LaunchEFRadioList_Create/", _near(_label("KM StandAlone Author Home")))


    2)
    _button("Launch")
    or
    _button("Launch", _near(_label("KM StandAlone Author Home")))

    Regards,
    Narayan
  • keithkeith Members
    Thanks Narayan.

    With _button("Launch", _near(_label("KM StandAlone Author Home"))) what if instead we want to not reference the button with the ID, but use only the attribute of title='Launch'?

    _button(title='Launch', _near(_label("KM StandAlone Author Home")))
    How would the syntax look for this?
    I'm guessing it would be like this?
    _button(_getAttribute("title","Launch"), _near(_label("KM StandAlone Author Home")))



    Thanks
    Keith
  • narayannarayan Administrators
    Hi Keith,

    Sahi automatically looks for various attributes on the button. I just checked that title is not one of them currently.
    We have added documentation on how to fix this: http://sahi.co.in/w/tweaking-sahi-apis

    After the changes you will be able to use
    _button("Launch", _near(_label("KM StandAlone Author Home")))

    Regards,
    Narayan
  • keithkeith Members
    Thanks Narayan,
    The FAQ will be useful to adapt for custom attributes.
    I'm thinking it might be better if I can pass the intended attribute name and expected value into a function so Sahi could identify any attribute label name and value from the calling script. Like _attribute("title","launch"). Would this be difficult to add such a script method?

    Thanks
    Keith
  • narayannarayan Administrators
    Hi Keith, it should not be too tough. Have a look at the code in concat.js especially the function findTagHelper

    Regards,
    Narayan
Sign In or Register to comment.