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.

Deleting Action through Image

mrkkhattakmrkkhattak Members
edited November -1 in Sahi - Open Source
I have a page which has listing as the following:

delImg First Name
delImg Second Name
delImg Third Name
delImg Fourth Name

When I record an action for it by clicking on delImg for 4th item (which is an image), it records the following into scripting:
_click(_image(42));

When I play this it successfully deletes it. But if I run the same script again it will not find that 4th Item and because it looks for this delImg on exact that location as recorded.

Can anyone suggest any work around for such scenario where it could explicit look for the name 'Fourth Name' and if that exists only then it try to delete it using the image?

Comments

  • narayannarayan Administrators
    Depending on your application, it could be either:

    _image(0, _near(_div("Fourth Name")));

    or

    _image(0, _in(_div("Fourth Name")));


    If you could post the HTML for this section it would be easier to help.
  • Thanks Narayan for your quick help.

    This is the actual html:
    _click(_image("Configuration"));
    _setValue(_textbox("//root/tags/tag__name='myContent']/attributes/attribute__name='name']"), "MRKNEW2");
    _setSelected(_select("//root/tags/tag__name='myContent']/tags/tag__name='allowWork']"), "true");
    _click(_submit("Save"));
    
    _click(_image(41)); // clicking this will open edit page 
    

    Here when playing this script it is possible that the system on which I am running this script as part of my regression test might not have the edit / delete image at this specific location.

    How could I post an image here so that I could show you the actual portion which is having this issue?

    I also don't see the link for Sahi API documentation is not working. Can you please also fix that?
  • narayannarayan Administrators
    That is the actual Sahi script :) Would like to see the HTML. (View source page, and copy relevant portion)

    Is this link not working for you: http://sahi.co.in/w/sahi-apis ? There have been some problems with the hosting recently. Could you please recheck?

    Regards,
    Narayan
  • Ah ... I posted Sahi script :( Here is the HTML for one row from the listing:
    <tr>
    <td colspan='5' width='950'>
        <table class='sc-table' cellpadding='0' cellspacing='0' id='MRK1_MyContent:MRKNEW2Updated' style='display:none;'>
        </table>
    </td>
    </tr>
    <tr class='tr2'>
    <td class='sc-col1'>
    <a href="#" onClick="javascript:action('NCMS[name=\'MRK1\']**myContent[name=\'MRKNew\']', 'Add')">
    <img src='/Public/Images/BT_add_B.png' border='0' align='absmiddle' /></a>
    
    <a href="#" onClick="javascript:action('NCMS[name=\'MRK1\']**myContent[name=\'MRKNew\']', 'Edit')">
    <img src='/Public/Images/BT_edit_B.png' border='0' align='absmiddle' /></a>
    
    <a href="#" onClick="javascript:action('NCMS[name=\'MRK1\']**myContent[name=\'MRKNew\']', 'Delete')")">
    <img src='/Public/Images/BT_delete_B.png' border='0' align='absmiddle'/></a>
    
    </td>
    <td class='sc-col2'>
        <div style='display: none;' id='MRK1_myContent:MRKNew_down'>
            <img src='/Public/Images/arrow-d.gif' width='11' height='11' align='absmiddle'>
        </div>
    <div id='MRK1_MyContent:MRKNew_right'>
        <img src='/Public/Images/arrow-g.gif' width='11' height='11' align='absmiddle'></div>&nbsp;</td>
    <td class='sc-col3'><strong>MRK1:myContent:MRKNew</strong></td>
    <td class='sc-col4'>&nbsp;</td>
    <td class='sc-col5'>&nbsp;</td>
    </tr>
    

    Yes. The API link seems to be working fine for me now. Thanks for checking it too.

    -Meraj
  • narayannarayan Administrators
    I think

    _image("BT_delete_B.png", _near(_cell("Fourth Name")));

    is what you need.

    (I did not see where the name was in the html you sent. Assuming that MRK1:myContent:MRKNew is the name.)

    Btw, try simplifying the identifiers for you textbox and selectbox, by using some other alternate identifier; they seem to be quite complex.

    Regards,
    Narayan
  • Thanks Narayan. Yes it is quite complex html structure. Based on the input field names and id we generate xml beshind scene on posting.

    Sahi is handling this very nicely, I was only having this issue where I wanted to edit / delete something from the list specifically. I will try as you mentioned and update here.

    Best regards,
    - Meraj
  • I tried with the following two scripts:
    _click(_image("Configuration"));
    _click(_link("NCMS(s) Listing"));
    _click(_image("BT_edit_B.png", _near(_cell("MRK1:myContent:MRKNew"))));
    

    For the above I am getting this error 'Reference Error: _near is not defined'.
    _click(_image("Configuration"));
    _click(_link("NCMS(s) Listing"));
    _image("BT_edit_B.png", _near(_cell("MRK1:myContent:MRKNew")));
    

    For this one I am getting this error 'JSERROR TypeError: Cannot find function _image.'

    Probably I am using an old Sahi version (Build: 2009-01-21)?
  • narayannarayan Administrators
    Yes Meraj, that is a very old version. Pick the latest release.
  • Updated but on running the latest Sahi I am seeing this in the command prompt:
    >>>> Sahi started. Listening on port: 9999
    >>>> Configure your browser to use this server and port as its proxy
    >>>> Browse any page and CTRL-ALT-DblClick on the page to bring up the Sahi Cont
    roller
    Sahi OS properties file = F:\software\testing-qa\sahi\sahi_20091130\config\os.pr
    operties
    keytool command may not be correct: Cannot run program "keytool": CreateProcess
    error=2, The system cannot find the file specified
  • narayannarayan Administrators
    Meraj, ignore that warning. I will add a documentation page on why that occurs. It is only useful for SSL and you can fix it by adding java/bin to your path or modifying keytool.path in sahi.properties or userdata.properties.

    Btw, scripts have moved into userdata directory, so you may want to copy your existing scripts folder into userdata.

    -Narayan
  • Yes. I see this warning but am able to play and record scripts without any issue.

    My problem has also been solved after using _near method as you mentioned:
    _click(_image("BT_edit_B.png", _near(_cell("NCMS:MyContent:MRKNew2"))));
    

    I hope it works fine with multiple rows when run in actual regression test and only click edit button on the row where it has this 'NCMS:MyContent:MRKNew2' text.

    Thanks for all your help.

    regards,
    -Meraj
Sign In or Register to comment.