Wait Method (Page Objects)

Applies to TestComplete 15.0, last modified on October 19, 2021

Description

Use the Wait method to pause the test run until a web browser loads the specified web page completely. After the page is loaded, TestComplete updates the reference to the page object to keep it valid.

Note: If the web page redirects to another web page, call the Wait method for the resulting page rather than for the initial page.

Declaration

TestObj.Wait(WaitTime)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
WaitTime [in]    Optional    Integer Default value: -1   
Result String

Applies To

The method is applied to the following object:

View Mode

To view this method in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.

Parameters

The method has the following parameter:

WaitTime

Specifies the time (in milliseconds) to wait until the browser loads the page and becomes ready to accept user input. If WaitTime is omitted, the timeout is specified by the project's Web page loading timeout option. After the specified time limit is reached, the test execution proceeds.

Result Value

The Wait method returns the URL of the page or resource that was loaded last on the page. If the web page does not contain frames and the page was loaded successfully, the Wait method returns the page’s URL. If the page contains frames, the method will return the URL of the last page that was loaded in the frame.

If the loading was not successful or the page was not loaded before the time limit specified by the WaitTime parameter was reached, the method returns an empty string.

Remarks

  • To determine whether the specified web page has loaded completely:

    The described mechanism of determining whether a web page has been downloaded completely is acceptable only for static web pages and is not effective for pages with dynamic content. For more information, see Wait For Web Pages and Waiting for Web Pages in Hybrid Mobile Applications (Legacy).

  • You can also wait until the current page is loaded by using the Wait or WaitPage method of the parent window object of the Page object.

  • If a user presses the Stop button in Internet Explorer when the Page.Wait method is running, the script execution will not be resumed. As a result, the test run will need to be interrupted manually.

Example

The following example finds a link on the page currently opened in the web browser, clicks the link and waits for the target web page to be loaded.

JavaScript, JScript

function WaitPageSample()
{

  var url = "http://smartbear.com/";
  Browsers.Item(btIExplorer).Run(url);
  var page = Sys.Browser("iexplore").Page(url);

  // Finds the Link object on the page
  var link = page.NativeWebObject.Find("href", "http://smartbear.com/free-trials", "A");

  // If the link is found
  if (link.Exists)
  {
    // Clicks the link
    link.Click();
    // Waits until the target page is loaded
    page.Wait();

    …
  }
  …

}

Python

def WaitPageSample():

  url = "http://smartbear.com/"
  Browsers.Item[btIExplorer].Run(url)
  page = Sys.Browser("iexplore").Page(url)

  # Finds the Link object on the page
  link = page.NativeWebObject.Find("href", "http://smartbear.com/free-trials", "A")

  # If the link is found
  if (link.Exists):
    # Clicks the link
    link.Click()
    # Waits until the target page is loaded
    page.Wait()

    # ...
  # ...

VBScript

Sub WaitPageSample

  url = "http://smartbear.com/"
  Browsers.Item(btIExplorer).Run(url)
  Set page = Sys.Browser("iexplore").Page(url)

  ' Finds the Link object on the page
  Set link = page.NativeWebObject.Find("href", "http://smartbear.com/free-trials", "A")

  ' If the link is found
  If link.Exists Then
    ' Clicks the link
    link.Click
    ' Waits until the target page is loaded
    page.Wait

    …
  End If
  …

End Sub

DelphiScript

procedure WaitPageSample();
var url, page, link;
begin

  url := 'http://smartbear.com/';
  Browsers.Item(btIExplorer).Run(url);
  page := Sys.Browser('iexplore').Page(url);

  // Finds the Link object on the page
  link := Page.NativeWebObject.Find('href', 'http://smartbear.com/free-trials', 'A');

  // If the link is found
  if link.Exists then
  begin
    // Clicks the link
    link.Click();
    // Waits until the target page is loaded
    page.Wait();

    …
  end;
  …

end;

C++Script, C#Script

function WaitPageSample()
{

  var url = "http://smartbear.com/";
  Browsers["Item"](btIExplorer)["Run"](url);
  var page = Sys["Browser"]("iexplore")["Page"](url);

  // Finds the Link object on the page
  var link = page["NativeWebObject"]["Find"]("href", "http://smartbear.com/free-trials", "A");

  // If the link is found
  if (link["Exists"])
  {
    // Clicks the link
    link["Click"]();
    // Waits until the target page is loaded
    page["Wait"]();

    …
  }
  …

}

See Also

Classic Web Testing
NativeWebObject.Find Method (Page Objects)
ToUrl Method (Page Objects)
Wait Method
WaitPage Method (Window Objects)
Wait For Web Pages
Testing Hybrid Mobile Applications (Legacy)

Highlight search results