Micro Focus QTP (UFT) Forums

Full Version: Xpath based Identification in QTP 11.0
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Xpath object identification is a new feature in QTP 11. Here is an example I would like to share.
Code:
Dim oPage  
Set oPage=Browser("name:=Google").Page("title:=Google")  
oPage.WebEdit("xpath:=//INPUT[@name='q']").Set "learnqtp" 'Entering value in Google textbox.  
oPage.WebButton("xpath:=//INPUT[@value='Google Search']").Click'Clicking Google Search button.

For those of you who doesn't know what an xpath is...
In simple terms its a unique address of a particular element in a webpage.
Hi Ravi,

could you please specify what are the advantages of using XPath identification rather than standard identification by either descriptive properties of the object in the code or using the object repository, if you use anyway, a property and a value for the identification in XPath (ex. value=Google Search)

Thanks Smile
Roy.
Xpath for a particular object is unique.We may think of it as an address location for a particular object which is unique.Hence object identification is easy.We need not look of multiple properties for unique identification of an object.In scenarios where properties doesn't make unique description , xpath makes the job easy and enhances performance(time spent in comparing multiple properties is saved).However performance depends on relative/absolute xpath given.Both paths point to the same object.
Hope this clarifies your query Smile
Hi,

Just another query: what would be more advantageous, Having xpath based identification of objects or html id?
Both will be unique I guess.
I think if i understand Ravi correctly, I can summarize the difference between the standard property identification of QTP and XPath method:

Standard properties identifications (descriptive/OR) says to QTP:
"Go search for ALL objects in a specific hierarchy that match a set of property values, hopefully the properties match a single object"

XPath identification says to QTP:
"Hey! I'm here! (or not here), You have a direct reference to me!, no need to search for anything"

its kind of abstracted but hope this helps.

Roy.
Hi

shall u please tell me,how to work with webelement using Xpath
for example getroproperty of an webelement
Hi,

Consider the below HTML object
<INPUT class="hover" id=1452 size=45 value="Enter id" name=n>
Now we can identify this object using various XPATH combinations.Few examples shared below
  • //INPUT[@class='hover']
  • //INPUT[@id='1452']
  • //INPUT[@id='1452',@class='hover']

By using such XPATHS, we can also limit our object search.For instance;if we want access to an object inside a WebTable Cell, we know that the object will have a parent with a TD html tag.In which case we can use XPATH like
//TD//INPUT[@name='n'

Regards,
Ravi
Nice info bro. I use 11 but never heard of it.
--------------------------------------------------
Very helpful ravi
thanks
I'm Glad you found the thread useful....
Pages: 1 2