Knowledgebase

Search:     Advanced search

Capturing Web Page Text with Functions

Article ID: 794  |  Last updated: 23 Dec, 2014

Web page text is not captured and saved in the application repository during recording because it is not a property of a window or control. If you want to perform actions based on web page text or verify that the text is correct, you can use functions that examine HTML code and return text.

The ExtractHTMLToString function returns the HTML in a specified window as a string. The HTMLFindByID and HTMLFindByTag functions examine the returned string and return the text in a specified HTML element ID or tag.

Using the HTMLFindByID function

The HTMLFindByID function returns a string that contains the inner text of the tag with the specified HTML element ID. The following example shows how this function is used to return the ticket number from a confirmation web page.

htmlText = ExtractHTMLToString("WysiCorp Thank You") 
ticketNum = HTMLFindByID(htmlText, "ticket")
If ticketNum = "" then
   Fail("Could not find the ticket number")
Else
   PrintLn("The ticket number is " & ticketNum)
End If

  • The htmlText variable is declared. Its value is the HTML returned from the WysiCorp Thank You page using the ExtractHTMLToString function.

  • The ticketNum variable is declared. Its value is the string returned by the HTMLFindByID function, which examines the HTML returned to the htmlText variable and returns the text with the "ticket" element ID. For example, the following HTML shows the ticket element ID and value.
    <td bgcolor="#DDF8D8" id="ticket">W72236</td>

  • The If statement fails the script if no text is returned by the HTMLFindByID function. If text is returned, "The ticket number is" followed by the ticket number is printed in the Output window.

Using the HTMLFindByTag function

The HTMLFindByTag function returns an array of strings that contains the inner text of the HTML element with the specified element tag. The following example shows how the HTMLFindByTag function is used to return the text in tags.

htmlText=ExtractHTMLToString ("WysiCorp List")
tag = HTMLFindByTag(htmlText,"p")
If Left(tag(2), 9) <> "CustomerB" then
   Fail("Could not find the customer")
Else
   PrintLn("The customer is " & tag(2))
End If

  • The htmlText variable is declared. Its value is the HTML returned from the WysiCorp List page using the ExtractHTMLToString function.

  • The tag variable is declared. Its value is an array of strings returned by the HTMLFindByTag function, which examines the HTML in the htmlText variable and returns the text within all of the tags. For example, if the page contains three tags, the array contains three strings. Each string is accessed using the array index (1, 2, or 3). 

  • The If statement fails the script if the characters returned by the Left function are not equal to "Customer B". The Left function returns the first 9 characters of the string stored as index 2 of the array in the TAG variable. If "Customer B" is returned, "The customer is" followed by the value of array index 2 is printed in the Output window.

Article ID: 794  |   Last updated: 23 Dec, 2014
Tags
web page text HTML

Prev   Next
OpenRecordsetQuery Statement Returns Database Engine Could Not...     Controls Duplicated in the Application Repository