Using DESCRIPTIVE PROGRAMMING, how QTP11, can find the Link (Web Link) in the web page

qtp

I am new to QTP and am trying to use version 11 to automate my project.

Using descriptive programming, how QTP can find a link in a web page. The HTML for the link is written in the Onclick function (like onclick="navigationClick('Link Name');)

I tried this:

If Browser(Browsername).Page(Pagename).Link("html tag:='Value',"id:=X","title:=Y","class:=Z").Exist(50)Then
   Browser(Browsername).Page(Pagename).Link("html tag:='Value',"id:=X","title:=Y","class:=Z").click

Else

 MsgBox "Link cannot be found"

But when i run the script, it always shows Link Cannot be found.

Note:

Using the same descriptive programming, i can able to find the link in the web page, if the HTML for the link is wrriten as OnClick='javascript.navigationClick(Link);"href='javascript:void(0);

Best Answer

On second reading of your question I think the problem is that the link you're trying to identify doesn't have an href. QTP does not consider links with no href to be real links. Perhaps if you try to use a WebElement rather than a Link the identification will succeed.

Also note that QTP uses the html id property instead of the DOM's id.

Browser(B).Page(P).WebElement("html tag:=A", "html id:=X").Click

(my original answer follows)


You can access the onclick attribute by using the attribute/ syntax for accessing native DOM attributes.

Browser(B).Page(P).Link("attribute/onclick:=navigationClick\('Link Name'\);")

Note that descriptive programming uses regular expressions so you have to escape special characters (like the parentheses in this example).

Related Topic