Wait Method (Page Objects)

Applies to TestComplete 14.30, last modified on November 21, 2019

Description

Use this method if upon clicking a hyperlink on a web page you need to pause test execution until the referred page is completely loaded in the web browser. Note that using the Wait method does not make the given reference to the Page object invalid.

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 script run will need to be interrupted.

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

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

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

Highlight search results