Forum Discussion

whuang's avatar
whuang
Regular Contributor
5 years ago

Page wait method doesn't wait the time I provided

Hi there,

 

I was using sys.browser("*").Page("*WebStore/Checkout*").Wait(60000) to wait for my page, but it only waited for 5 seconds and then execute the next line. Does anybody know why and how I can fix it?

 

Thanks in advance!

  • Hi,

     

    what wait method should I use if I want to wait for the next page to be fully loaded

    Unfortunately, such method does not exist because the definition of the "fully loaded" page is specific to every given web page (an web application).

    The generic approach is like this:

    -- For every tested web page you must determine some web element (let's call it anchor) that: a) must exist on the page in order your test code can continue; and b) web page must be responsive when this anchor web element appears on the page (i.e. page can process user input when anchor element appears on it). This will be a definition of "fully loaded page" for this given page. For other page the anchor element might appear to be different, but the approach remains the same;

    -- Use page.Wait() call every time a new page is requested from web server as a result of the click on some web element (link, button, etc.). This step can be skipped if the click does not initiates load of the new page but just triggers some script that changes page's DOM;

    -- After .Wait() method returns, you should use the proper WaitXXX or FindXXX method (WaitAliasChild, FindChild, etc.) and use it in a loop until the anchor web element appears on the page. When the anchor web element appears on the page this means that the page is fully loaded and your test code may continue.

     

    P.S. Note, that the above approach does not necessarily assume that all web elements have been loaded. But if you need this, then the approach remains the same - you must somehow determine what web element is loaded last and wait until this last web element is loaded.

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    > Does anybody know why and how I can fix it?

    Because the page source was obtained from the server within 5 seconds.

    As per documentation, .Wait() method waits for the page to be obtained from the server and the browser is ready to process user's input. Note, that this time does not include the time required for all scripts embedded on the page to complete. As well as it does not include the time required for all bells and whistles that all modern web pages are full of (AJAX) to finish. This is specific to every web page and you need explicitly wait for this or that element that is essential for your test to appear on the page before proceeding further.

     

    • whuang's avatar
      whuang
      Regular Contributor

      Thanks for your answer, so what wait method should I use if I want to wait for the next page to be fully loaded and then execute the next line of code? What happens right now is I use this wait method, and it only waited for a few seconds and then execute the next line, but the browser was still processing on the previous page, that spinning circle was still spinning on the  browser tab. Below is the screenshot from the test log where TC failed to wait for the page I specified.

       

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        what wait method should I use if I want to wait for the next page to be fully loaded

        Unfortunately, such method does not exist because the definition of the "fully loaded" page is specific to every given web page (an web application).

        The generic approach is like this:

        -- For every tested web page you must determine some web element (let's call it anchor) that: a) must exist on the page in order your test code can continue; and b) web page must be responsive when this anchor web element appears on the page (i.e. page can process user input when anchor element appears on it). This will be a definition of "fully loaded page" for this given page. For other page the anchor element might appear to be different, but the approach remains the same;

        -- Use page.Wait() call every time a new page is requested from web server as a result of the click on some web element (link, button, etc.). This step can be skipped if the click does not initiates load of the new page but just triggers some script that changes page's DOM;

        -- After .Wait() method returns, you should use the proper WaitXXX or FindXXX method (WaitAliasChild, FindChild, etc.) and use it in a loop until the anchor web element appears on the page. When the anchor web element appears on the page this means that the page is fully loaded and your test code may continue.

         

        P.S. Note, that the above approach does not necessarily assume that all web elements have been loaded. But if you need this, then the approach remains the same - you must somehow determine what web element is loaded last and wait until this last web element is loaded.