Micro Focus QTP (UFT) Forums
How to capture dynamically changing element ids of a text box? - 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: How to capture dynamically changing element ids of a text box? (/Thread-How-to-capture-dynamically-changing-element-ids-of-a-text-box)



How to capture dynamically changing element ids of a text box? - pmishra - 06-29-2011

Hi,
I am writing scripts for a web page, which has 7 edit boxes. The element id of each box is unique. The element ids are changing dynamically each time you invoke the page. I inspected the properties of the edit boxes using developer tool bar and below are the details:
Code:
EditBox1 : <input type="text" title="ETC: 6.40" alt="ETC: 6.40" class="formFieldNoWidth" maxlength="" size="4" value="" id="d91519e189" name="actuals_hours">
EditBox2: <input type="text" title="ETC: 6.40" alt="ETC: 6.40" class="formFieldNoWidth" maxlength="" size="4" value="" id="d91519e198" name="actuals_hours">
EditBox3: <input type="text" title="ETC: 6.40" alt="ETC: 6.40" class="formFieldNoWidth" maxlength="" size="4" value="" id="d91519e206" name="actuals_hours">
I cleared the caches of the page and again invoke the same page. Now I inspect the same edit boxes using Developer tool bar. Now the element ids of the pages have been changed. Below are the details:
Code:
EditBox1 : <input type="text" title="ETC: 6.40" alt="ETC: 6.40" class="formFieldNoWidth" maxlength="" size="4" value="" id="d96132e187" name="actuals_hours">
EditBox2: <input type="text" title="ETC: 6.40" alt="ETC: 6.40" class="formFieldNoWidth" maxlength="" size="4" value="" id="d96132e196" name="actuals_hours">
EditBox3: <input type="text" title="ETC: 6.40" alt="ETC: 6.40" class="formFieldNoWidth" maxlength="" size="4" value="" id="d96132e204" name="actuals_hours">
Can you please suggest , how can I write the script in such a way that even if the element id changes should not affect my script? I have been asked to write the script using element id only.
Regards,
Pinaki


RE: How to capture dynamically changing element ids of a text box? - parminderdhiman84 - 06-29-2011

Hi,

Did you try using descriptive programming.

Regards,
Parminder


RE: How to capture dynamically changing element ids of a text box? - pmishra - 06-29-2011

Yes I tried. But the class name is same for all the boxes. Only the element ids are changing dynamically.
Can you provide any sample code ?


RE: How to capture dynamically changing element ids of a text box? - parminderdhiman84 - 06-29-2011

Hi,

Please see if this solves your problem:

Code:
Set oDesc=Description.Create()
oDesc("micclass").value="WebEdit"
Set obj_coll=Browser().Page().ChildObjects(oDesc)
obj_Coll.item(0).Set "test1"
obj_Coll.item(1).Set "test2"

you can check in which edit box "test1" is entered and similarly you can enter values in all the 7 edit boxes just by changing the item number

Regards,
Parminder


RE: How to capture dynamically changing element ids of a text box? - rajpes - 07-05-2011

Forget about qtp for a while, how will we ourself recognize those edit boxes uniquely when the only property known itself keeps changing?
You will have to ensure uniqueness! ask the developers to give unique "name" to the text boxes or find out why the id is changing