Monday, January 2, 2012

More Xpath for Web Objects

Identifying using Id attribute
obj.WebEdit("xpath:=//input[@id='htmlID']").Set "QTP"
Identifying using Type attribute
obj.WebEdit("xpath:=//input[@type='text'][1]").Set "QTP"'Setting value in first textBox
Identifying using Tagname
obj.WebList("xpath:=//select[1]").Select "London"'Highlighting first listBox
Identifying using Innertext
obj.Link("xpath:=//a[.='Google']").Click'Clicking Google link
Identifying WebTable based on Rowcount
obj.WebTable("xpath:=//table[count(.//tr)=2]").Highlight 'Highlighting the table which has only two rows


More examples will be added

10 comments:

  1. Could you please clarify, what QTP versions support xpath?

    ReplyDelete
  2. Hi,
    In my application there are two links with same name.

    how to get the xpath for first link and second link .(" manage my cookies')
    make sure clear all cookies.
    url: http://www.hertzondemand.com/london

    ReplyDelete
    Replies
    1. Hi ,

      I am trying automate workflow application having number of web element where i want to click on particular web element but QTP is taking more than 3 min to run single line of script or fails to click.

      Can it is possible identify web element with Xpath method for dynamic objects or web element
      Is there any other method other than click ,to work faster.

      Browser().page().frame().Webelement(AB11).Click
      Browser().page().frame().Webelement(AB12).Click

      Thanks in advance
      Rajesh

      Delete
  3. Excellent Post.Also Visit http://www.whiteboxqa.com/WBQA/SEO/qtp-videos.php

    ReplyDelete
  4. Is it possible to use regular expression in xpath

    I am having xpath using div

    Bro().page().webelement("xpath:=//div[contains(text(),'"&variable&"')]. Here the variable is text. It's working great for all the text.

    1 case, I have a text with ' - (e:g: Are you taller than 56') - In this case it fails, I can pass the string to specific characters,avoiding ',
    however is it there any way to handle this dynamically?

    ReplyDelete
  5. Asiq Ahamed :

    Could you please elaborate more on how to get the XPath from the Source code ??
    (OR) How to identify the xpath of a particular object in AUT ??

    Thanks in Advance.

    ReplyDelete
  6. To get Xpath use 'Firebug' add in, which is available for both Chrome and Firefox browsers........

    ReplyDelete
  7. very informative data about qtp codes i.e., identifying attribute, tagname, innertext QTP and QC Online Training Hyderabd

    ReplyDelete
  8. very useful info, and please keep updating........
    Thanks

    ReplyDelete