Accessing DOM document Object

Applies to TestComplete 14.20, last modified on September 11, 2019

TestComplete lets you access the HTML DOM document object of web pages. You can use it in your tests to get specific DOM-related data from the web page.

To access a web page’s DOM document object, use the contentDocument property of the Page test object. Similarly, to get the document object of a frame, use the contentDocument property of the Frame test object.

The following example demonstrates how you can use the DOM document.title property to get the web page title:

Keyword test that gets the contentDocument.title property value

JavaScript, JScript

function Test()
{
  Browsers.Item(btIExplorer).Run("http://smartbear.com/");
  var page = Sys.Browser().Page("https://smartbear.com/");
  Log.Message(page.contentDocument.title);
}

Python

def Test():
  Browsers.Item[btIExplorer].Run("http://smartbear.com/");
  page = Sys.Browser().Page("https://smartbear.com/");
  Log.Message(page.contentDocument.title);

VBScript

Sub Test
  Dim page
  Browsers.Item(btIExplorer).Run "http://smartbear.com/"
  Set page = Sys.Browser.Page("https://smartbear.com/")
  Log.Message page.contentDocument.title
End Sub

DelphiScript

procedure Test;
var page;
begin
  Browsers.Item(btIExplorer).Run('http://smartbear.com/');
  page := Sys.Browser.Page('https://smartbear.com/');
  Log.Message(page.contentDocument.title);
end;

C++Script, C#Script

function Test()
{
  Browsers["Item"](btIExplorer)["Run"]("http://smartbear.com/");
  var page = Sys["Browser"]()["Page"]("https://smartbear.com/");
  Log["Message"](page["contentDocument"]["title"]);
}

For information on the properties and methods of the DOM document object in different browsers, follow these links:

Remarks

  • The contentDocument property is a native property of web pages in Chrome, Firefox, Edge and Internet Explorer 10 and later.

  • If you use the DOM or Hybrid object model for your web tests, the DOM document object is also available as the Page.document test object. However, working with a native DOM document using the Page.contentDocument property enables you to reuse test snippets across tests that use different web object models.

See Also

Testing Web Applications
Cross-Browser Testing in TestComplete
Common Tasks for Web Testing
Executing JavaScript on Web Pages
Accessing Native Web Attributes and Methods
Getting CSS Attributes

Highlight search results