Reflection 2014 .NET API Guide
Get Text from a Web Page

This sample program shows how to get text from a Web page document that's open in Reflection. To do this, we get a Web control object to access the Web page document and then use the XPATH to identify the Web element (text) on the page, as follows:

IWebElement WebElement = WebDocument.GetElement("HTML/BODY/TABLE/TBODY/TR[1]/TD[1]")

You can also use the ID to work with Web elements. For an example, see Integrate Web and Host Data.

To create a Web page document

  1. Using a text editor, such as Notepad, create a new text file called table.htm.
  2. Copy this HTML code into the text file, and then save the file.
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head>

      <title>HTML Test Page</title>

    </head>

    <body>

      <table border="1">

      <tbody>

        <tr id="first-table-tr">

          <td id="USDOLLAR">U.S. Dollars</td>

          <td>1</td>

          <td>1.3240</td>

          <td>108.25</td>

          <td>0.8114</td>

        </tr>

        <tr>

          <td>Canadian Dollars</td>

          <td>0.7553</td>

          <td>1</td>

          <td>81.7598</td>

          <td>0.6128</td>

        </tr>

        <tr>

          <td>Euros</td>

          <td><br>1.2325</br></td>

          <td>1.6318</td>

          <td>1</td>

          <td>133.4181</td>

        </tr>

        <tr>

          <td>Japanese Yen</td>

          <td>0.009238</td>

          <td>0.012231</td>

          <td>0.007495</td>

          <td>1</td>

        </tr>

      </tbody>

      </table>

    </body>

    </html>

  4. In Reflection, create a new Web page document and type the file path to table.htm in the URL box. For example, if you saved the file to

    C:\Users\user_name\Documents\Attachmate\Reflection\

    type the following path (in one continuous string):

    file:///C:/Users/user_name/Documents/Attachmate/Reflection/table.htm

  5. Name the Web page document Webtable.urlx and save it to the same location as "table.htm."
  6. Quit, and then restart Reflection.
  7. In Visual Studio, create a new Console Application project. In the New Project dialog box, type Get a Web Object in the Name box.
  8. Select the Create directory for solution box, click Browse to select your API projects folder (for example, C:\MyProjects), and then click OK.
  9. In Solution Explorer, add the class assemblies. (For instructions, see Create an API Project.)
  10. Copy the code from Get a Web Object, paste it to the Program.cs tab, and then edit the path in the code to match the path to which you saved Webtable.urlx.
  11. Build the application (Build > Rebuild Solution) and then run it (Debug > Start Without Debugging).

A console box should appear with the text extracted from Webtable.urlx: "The currency conversion rate from Canadian to U.S. Dollar: [number]. Press any key to continue..."