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.

Wait for reload?

MultiMikeMultiMike Members
edited November -1 in Sahi - Open Source
We have a web application that uses custom buttons (actually tables) with onClick events to submit forms.
For example:

<form>
<table onClick="submitForm()" class="button">...</table>
</form>

And when recording scripts in Sahi, it doesn't wait for the form submission
to complete before proceeding with the execution.

The only scheduler function I've seen that may help is "wait", but it's not very appropriate for the situation.

Is it possible to wait for the next request to complete in any other way?

/Mikael

Comments

  • narayannarayan Administrators
    Mikael, ideallly it should automatically wait. If it does not, then you could put a _wait(1000). If you could point us to a page, we can have a look at this problem.
  • Thanks for the quick answer.
    We actually got it to work now, so no need to use "wait". :-)

    /Mikael
  • I'm still a little worried about this issue.
    Today it appeared on a collegues computer also.

    Can you inform us how Sahi detects what scripts shall be injected into which page?
    Ie, how does it know when to wait after a command and when not to?

    /Mikael
  • narayannarayan Administrators
    edited January 2008
    Sahi injects scripts into all pages which it thinks has html content.
    It will not inject the script into AJAX responses.

    Sahi waits if any part of the web page is loading. Be it a frame/iframe request or an AJAX request. But if the server takes a long time to respond on a non-AJAX call, and hence the current page is not unloading, then Sahi may go ahead and execute the next statement since it does not know that there is something that is yet to be loaded.

    Eg.

    Page1
    ---
    Link to Page2
    buttonA
    ---
    
    Page2
    ---
    buttonA
    ---
    
    And the script is
    _click(_link('Link to Page2'));
    _click(_button('buttonA'));
    
    If after executing _click(_link('Link to Page2'));, the server takes a long time to respond with Page2, the 'buttonA' of the first page may get clicked.
    So you may need to put an explicit wait in such a case.
    _click(_link('Link to Page2'));
    _wait(1000);
    _click(_button('buttonA'));
    
    Hope that helps.
  • Thanks for the explanation.

    Let's see if I got this right:
    1. A _click command is executed.
    2. Sahi waits a time (between every command)
    3. If a unload event is triggered, it waits for the new page.

    If this is the procedure, and the wait in step 2 is only ca 100ms, I guess it could be quite probable that the next command is executed to early?

    I think working around this with wait is unfortunate, because I would really like it to be deterministic,
    and it would be difficult to pinpoint all locations where the wait is needed.

    Is it possible to have a command that waits for a location to be loaded?
    For example:
    _waitLocation('http://localhost:8090/test.php');

    Or wait for a reload altogether:
    _waitReload();

    And the last question:
    Would it be safer if using items only accessible in the second page? for example:

    Page 1:
    Link to page 2
    Button1A
    
    and page 2:
    Button2A
    
  • narayannarayan Administrators
    There is a _wait(maxTime, condition);

    Have a look at http://sahi.co.in/w/_wait

    Yes, it is safer if using items only accessible in the second page.
  • Hi,

    I have a question similar to this, so I reuse this thread for it.

    How does sahi know when a web page is still loading and when it is fully loaded? What should be the condition to check for a page if it is fully loaded?

    Is there a possibility additionally to doing this check to reload the page after the timeout? The scenario here is the following: sometimes when a page shall be loaded, nothing happens, the browser 'hangs' forever with an empty page, but it might succeed to load the page if it reloads it.

    Best regards,
Sign In or Register to comment.