ExecMethod Method

Class

  • BrowserChild
  • HtmlCheckBox
  • HtmlColumn
  • HtmlComboBox
  • HtmlHeading
  • HtmlImage
  • HtmlLink
  • HtmlList
  • HtmlListBox
  • HtmlMarquee
  • HtmlPopupList
  • HtmlPushButton
  • HtmlRadioButton
  • HtmlTable
  • HtmlText
  • HtmlTextField

Action

Runs a JavaScript method or property on an object.

Availability

This functionality is supported only if you are using the Classic Agent.

Syntax

sReturn = HtmlObject.ExecMethod (sMethod)
Variable Description
sReturn The string returned by executing the JavaScript. If no value is returned, sReturn will be an empty string. STRING. (MAX SIZE 4096).
sMethod JavaScript method or property.
Note: JavaScript is case-sensitive.
STRING. (MAX SIZE 1024).

Notes

If the browser cannot evaluate a method or property after ExecMethod sends it, Silk Test Classic is unable to provide any further information, such as runtime errors, because it cannot retrieve them from the browser. Furthermore, Silk Test Classic cannot know how much or how little of the language set (JavaScript) that the browser supports.

Calling ExecMethod() on a BrowserChild executes the JavaScript against the ‘Window’ object for that frame. You can use it to access ‘document’ properties/methods of a frame. To do so, you must include ‘document’ in the ExecMethod() call:

TheFrame.ExecMethod ("document.<property>")

Examples

To find the HTML class name of an object:

STRING sHTMLClass = TheHtmlObject.ExecMethod("tagName")

To find the full HTML for an object:

STRING sFullHTML = TheHtmlObject.ExecMethod("outerHTML")
To refer to a 4Test object in ExecLine:
// This example prints the HTML class name of
the first JavaScript child element of the object
INTEGER iSourceIndex = Val
(TheHtmlObject.ExecMethod("sourceIndex"))
Print (BrowserPage.ExecLine
("document.all[{iSourceIndex}].children[0].tagName"))
To get the path name of a link:
STRING sPath = TheHtmlLink.ExecMethod('getAttribute("pathname")')
To find out whether a link is disabled:
STRING sDisabled = TheHtmlLink.ExecMethod('getAttribute("disabled")')
To get the onClick handler of an object:
STRING sOnClick = TheHtmlObject.ExecMethod('getAttribute("onclick")')
To get the background color of a frame:
STRING sBgColor = TheFrame.ExecMethod ("document.bgColor")

or

STRING sBgColor = TheFrame.ExecMethod ("document.body.currentStyle.backgroundColor")