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.

Not able to recognize object while playback

kplokeshkplokesh Members
edited November -1 in Sahi - Open Source
Hi,

In my application sahi is not recognizing few objects example I need to add existing documents clicking "Browse" button the property/Accessor is _file("versionFile") but while playing back it's not recognizing.

Can any suggest to handle this issue.

Thanks,
Lokesh.

Comments

  • Hi Lokesh,

    If you want to upload an exsiting document you will have to use: _setFile()

    For more Details: http://sahi.co.in/w/_setFile

    Let me know if you face any problem.

    Regards
    Sumitra
  • Hi Sumitra,

    Even I have used the same statement but file is not attaching, the below statements I have used,

    _setFile(_file("versionFile"), "C:\\Users\\lokeshk\\Desktop\\Test Documents\\Document Test 5.docx");
    _click(_button("Add"));

    Thanks,
    Lokesh.
  • Hi Lokesh,

    _setFile works in a round about way. It is not handled at the browser level. It is handled at the proxy. So you will not see the file input box being populated with your desired filename. But when the form is submitted, the proxy will add the correct file to the request before it sends it to your web server. But if there are javascript checks before form submit to see if the filename is non-empty, then the script will not work as desired.

    If there are javascript validations on the file field, you can try this hack. Before submitting the file, change the field’s type to “text”, and then set its value.

    In you case,
    // set the file
        _setFile(_file("versionFile"), "C:\\Users\\lokeshk\\Desktop\\Test Documents\\Document Test 5.docx");
           // Change the "type" attribute of file field
        if (_isIE()){
            _call(_file("versionFile").outerHTML = _file("versionFile").outerHTML.replace(/type=file/, "type=text"));
        }else{
            _call(_file("versionFile").type = "text");
        }
            // Set the value into the textbox
        _setValue(_textbox("file"), "C:\\Users\\lokeshk\\Desktop\\Test Documents\\Document Test 5.docx");
    

    Let me know if this solves your issue.

    Regards
    Sumitra
  • Hi Sumitra,

    Now it's working.

    Thanks,
    Lokesh.
This discussion has been closed.