Micro Focus QTP (UFT) Forums
retrieving values of fields from a web page - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: retrieving values of fields from a web page (/Thread-retrieving-values-of-fields-from-a-web-page)



retrieving values of fields from a web page - kordirko - 10-24-2012

Hi,
I am using QTP 11, Internet Explorer 7 and 8.
my Application has a web page that displays a table containing fields' names and their values.
I want to retrieve values of particular fields from this page.
I am facing a problem while retrieving these values because, depending on the user rights, a field can be displayed either as a WebEdit (user can edit the field's content)
or a WebElement (field is read only).
The same fields can be read only for one user, and editable for the other, and I cannot predict how the field will be displayed.

Below is an example how HTML code of this page looks like,
this code contains two fields: FieldName1 & FieldName2 with corresponding values: Value 1 and Value 2.
FieldName1 is editable, and FieldName2 is read only.
Code:
<table>
<tr>
    <td width="16" class="wcmFormRowEven">&nbsp;</td>
    <td nowrap="true" width="170" scope="row" class="wcmFormRowEven">FieldName1:</td>
    <td width="100%" class="wcmFormRowEven"><input size="42" type="text" title="Właściwość:FieldName1, Typ: ciąg" class="wcmFormText" maxlength="64" value="Value 1" name="FieldName1"></td>
</tr>
<tr>
    <td width="16" class="wcmFormRowEven">&nbsp;</td>
    <td nowrap="true" width="170" scope="row" class="wcmFormRowEven">FieldName2:</td>
    <td width="100%" class="wcmFormRowEven">Value 2<input disabled="true" value="Value 2" name="FieldName2" type="hidden"></td>
</tr>
</table>
I created two simple pages to illustrate the problem and to play with it:
http://mtvk.pl/kordirko/xx1.html
http://mtvk.pl/kordirko/xx2.html

Currently I use the below code to retrieve values from this page:
Code:
If Browser("Test page").Page("Test page").WebEdit("html tag:=INPUT", "class:=wcmFormText", "name:=FieldName1" ).Exist Then
      strValue = Browser("Test page").Page("Test page").WebEdit("html tag:=INPUT", "class:=wcmFormText", "name:=FieldName1" ).GetROProperty("default value")
ElseIf  Browser("Test page").Page("Test page").WebElement( "class:=wcmFormRowEven", "html tag:=TD", "innerhtml:=.*<INPUT disabled name=FieldName1 value=.*type=hidden>" ).Exist Then
     strValue = Browser("Test page").Page("Test page").WebElement( "class:=wcmFormRowEven", "html tag:=TD", "innerhtml:=.*<INPUT disabled name=FieldName1 value=.*type=hidden>" ).GetROProperty( "outertext" )
Else
    strValue = "ERROR!!!"
End if

MsgBox( strValue )
This code works fine, it tests if a WebEdit object exists on the page, if yes --> retrieve the value from the WebEdit, if not exists --> from the WebElement.
The problem is that I have to check hundreds of fields from many pages, 50% of fields are read only on avarage,
and the test for existence of fields takes ages.
How can I improve this code, is there any smarter way to manage this case? Please advice.