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 stop Sahi from closing a dialog automatically?

edited December 2012 in Sahi Pro
I am facing an issue in which I want to upload a file.
I do not want to use the bypass given by Sahi Team to upload a file.
(I am able to work with the bypass properly but my view was it will not be a proper testing)
I want to use an exe created by me in AutoItScript which fills in the value in the edit box and then clicks Open.
My script with upload.exe is working fine for IE and FF but not for Chrome.
It fails because the file upload dialog which appears in chrome is different. It has a title as "Open" and "Enter" key is fired when it is launched by the below method.
_call(_file("bfile0").click());
Thus I am not able to fill in the details of file using my upload.exe

Here is my code which is working fine for IE and FF but not for Chrome.
_popup("/NonModalWindow.*/")._call(_file("bfile0").click());
_wait(600);
_execute('"C:\\sahi_pro\\userdata\\scripts\\upload.exe" "C:\\Temp\\mylogfile.txt"', true, 2000);

So please let me know how to stop firing "Enter" key on a dialog and use my own upload.exe.
Thanks!
rahoolm

Answers

  • Just one more information is that when I do step by step replay using the Sahi Controller this script is successful and works fine without errors.
  • narayannarayan Administrators
    Hi Rahoolm,

    You can try clicking on the upload button itself using AutoIT. (We chose the bypass mechanism because of the same problems you encountered. The dialogs and behavior are different for different browsers.) When you click via Javascript, it may or may not work properly.

    Btw, could you please share your AutoIT script for others to benefit from it?

    Thanks,
    Narayan

  • Hello Narayan,
    Thanks for your reply. I was also thinking on the same lines on how to implement clicking on the button itself and then filling in the details and clicking on open button.

    Before I could share my autoit script which is in fact quite simple, I would like to know that whether it is possible to stop auto firing of enter on alert or prompt dialog. If yes could you please share the code.

    If there is something to be modified in the concat.js or any other setting let me know.

    Here are 2 things which I would like to share with the sahi team.
    AutoItScript for upload ( I am directly sharing the source code so that you can modify it as per your use)
    _navigateTo("http://www.sahi.co.in/demo/php/fileUpload.htm";);
    _call(_file("file").click()); // necessary for firefox
    // for IE I have added below line to concat.js and now it works _click(_file("file0"));
    this.addAD({tag: "INPUT", type: "file", event:"click", name: "_file", attributes: ["name", "id", "index", "className"], action: "_click", value: "value"});
    _wait(600);
    _execute('"D:\\sahi_pro\\userdata\\scripts\\upload.exe" "C:\\temp\\myfile.txt"', true , 2000);

    Auto it script - you need to compile it using F7
    ===================================START
    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_UseUpx=n
    #AutoIt3Wrapper_Compile_Both=y
    #AutoIt3Wrapper_UseX64=y
    #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
    #AutoIt3Wrapper_Add_Constants=n
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

    $title = "Choose File to Upload"
    $title1 = "File Upload"
    $title2 = "Open"
    If ($CmdLine[0]== 1) Then
    ;==> Check if the first argument is supplied to the exe or not
    $fileNameAndPath = $CmdLine[1]
    Else
    MsgBox(0,"Warning!",'Please provide Absolute fileNameAndPath like '&'"upload.exe '&'"C:\temp\myfile.txt""', 2)
    Exit
    EndIf


    If (WinExists($title)) Then ;==> For IE - check whether Dialog with Title "Choose File to Upload" exists or not
    ControlSetText($title, "", "Edit1", $fileNameAndPath)
    ControlClick($title, "", "&Open")
    ElseIf(WinExists($title1)) Then ;==> For FF - check whether Dialog with Title "File Upload" exists or not
    ControlSetText($title1, "", "Edit1", $fileNameAndPath)
    ControlClick($title1, "", "&Open")
    ElseIf(WinExists($title2)) Then ;==> For Chrome - check whether Dialog with Title "Open" exists or not NOT WORKING in playback
    ControlSetText($title2, "", "Edit1", $fileNameAndPath)
    ControlClick($title2, "", "&Open")
    Else
    MsgBox(0, "Error!", "Window not found!",2)
    EndIf
    ============================================END

    You can also create an exe with 2 arguments first for window name and second for file name.
    If you can embed it in the lib.js file like you did it for windowfocus.exe then it can be great thing.

    On similar lines we can create download exe. These kind of stuff is already used by some guys who are using selenium. Search on Google for that.

    One Last word for you and your team, you guys ROCK and Sahi is a great tool. Hats off to you!

    I would like to work for Sahi on part time basis free of cost , let me know if you have some work for me. Do contact me on my email id iwx1@in.com

    I have introduced Sahi in my org and I wanted them to purchase a license but unfortunately they are not yet ready and are still going with the Sahi OS version. Its a management decision :( I cant do much.

    I am also interested in the takeSnapShots(trure) API. Let me know if it is working fine now.

    Thanks again!
    Regards,
    rahoolm

  • Hi Rahoolm,

    If you want to see the alert/confirm/prompt/print pop-up with sahi itself, you can edit concat.js:

    serach in the concat.js for
    Sahi.prototype.mockDialogs = function (win)

    and the line
    return;
    at the first line of the function, like:
    Sahi.prototype.mockDialogs = function (win) {
    return;
    win.alert = this.wrap(this.alertMock);
    win.confirm = this.wrap(this.confirmMock);
    win.prompt = this.wrap(this.promptMock);
    win.print = this.wrap(this.printMock);
    };

    --
    Kshitij Gupta
  • Hello Kshitij,
    I tried what you said but still I was not successful in achieving that.
    Is there anything else you feel I should try ?
    Thanks in advance!

    regards,
    rahoolm
  • By the way, I created a jar by which I can execute auto it functions in sahi script.
    If anybody interested let me know.
  • Hi Rahoolm,

    I checked on IE, Chrome and FF and it worked as expected.
    After changing in the concat.js, please restart Sahi, clear browser cache and try.

    --
    Kshitij Gupta
  • Thanks Kshitij!
    I know it is working with the things you have mentioned.

    How to check whether the Open dialog is launched or not.

    I am facing issue only for File Upload - Open Dialog which appears on Chrome.

    If I run the script step by step it works but when I play the script it fails.

    Can you try at your end to check whether Open dialog for file upload is launched or not.

    Please let me know.

    Thanks again!

    regards,
    rahoolm
Sign In or Register to comment.