Getting started with Unified Functional Testing/QTP Test Case Code

'open the browser and go to login page ""
'systemutil.Run "iexplore.exe",""
fn_openApplication "iexplore.exe",""
'--- what object do we want to act on???---------------------------- what action do we want to take on that object
Set objBrowserPage = Browser("index:=0").Page("title:=.*")
objBrowserPage.WebEdit("html id:=user_login").Set "userName"
objBrowserPage.WebEdit("html id:=user_pass").SetSecure "password"
objBrowserPage.WebButton("html id:=wp-submit").Click
'Set up a checkpoint to validate that we have successfully logged in
If objBrowserPage.WebElement("innertext:=My Membership","html tag:=H1").Exist(10) Then
'Click on the Notes and Code Link in the browser
objBrowserPage.Link("innertext:=Notes and Code").Click
'Verify that the page opened that we expected
If objBrowserPage.WebElement("innertext:=Notes and Code","html tag:=H1").Exist(10) Then
Print "The test Passed!!!!!!"
End If
Print "The Membership page was not found"
End If

  • qinghua tong

    Hi sir,

    I went though all videos in Module 2, I followed the code in the video but UFT cannot identify the link “Notes and Code for Automation Testing” under “Automation Resource” using descriptive programming. Bellow is the code I used:

    systemutil.Run “iexplore.exe”, “”

    Set objBrowserPage = Browser(“index:=0”).Page(“title:=.*”)

    objBrowserPage.Link(“name:=log in with a password”).Click

    objBrowserPage.WebEdit(“html id:=user_login”).Set “username”

    objBrowserPage.WebEdit(“html id:=user_pass”).SetSecure “password”

    objBrowserPage.WebButton(“html id:=wp-submit”).Click

    If objBrowserPage.WebElement(“innerhtml:=My Membership”, “html tag:=H1”).Exist(2000) Then

    ‘cannot identify this link below
    objBrowserPage.Link(“href:=”, “html tag:=A”, “innerhtml:=Notes and Code for Automation Testing”, “innertext:=Notes and Code for Automation Testing”, “name:=Notes and Code for Automation Testing”, “outerhtml:=Notes and Code for Automation Testing“, “outertext:=Notes and Code for Automation Testing”, “text:=Notes and Code for Automation Testing”, “url:=”).Click

    End If

    I tried to use as many properties as I can but UFT still shows me that multiple elements are found.
    Can you give any suggestions? Thanks.

    • QTPtutorialnet

      Hey qinghua,

      I am glad to help. My first question is what page are you on and what link are you trying to click? Could you send me a screenshot or at least give me a clear url and description of what you are trying to click on? I am not sure which page you are on haha.

      One of the most important rules with element recognition is not to use as many identifiers as possible but: use the minimum # of properties required to get the job done. THe more identifiers you have, the easier it is for the test to break. Usually 1 or 2 properties should be sufficient.

      But, from a quick look at your code, i would just use href and an index to identify the correct link. Something like this Link(“href:=”, “index:=0”)

      • qinghua tong

        I want UFT to click “Notes and Code for Automation Testing” (see the screenshot)

        I use this code you provide and it works:
        Link(“href:=”, “index:=0”)

        which comes my next question: what is the reason to use “index:=0” here?
        My understanding of ordinal identifier is that when the web element is not unique, index can help. But I check the html source code of this page which tells me that this link is unique. So why use “index:=0” here? Thanks.

        • QTPtutorialnet

          Yes, you are correct, ordinal identifier helps us when there are 2 or more same elements on a page. So listening to your problem, I would bet that there are more than 1 of these links on the page. Also, the fact that adding the index fixed the problem tells me further that there are probably at least 2 of those objects. I wonder how you know that there is only 1 link on this page? After looking, i do see 2.

          Basically, a good rule of thumb is if you’re starting to add too many identifiers, stop, add an index instead and see what happens 🙂

          • qinghua tong

            Sorry I cannot find the second link object with the same href property. Can you tell me where is it? In debug mode I tried to use Link(“href:=”, “index:=1”).hightlight to highlight the second link object, after I hit enter, it jumped to the browser which means there is a second link object but it did not show any highlight. So what’s the problem here?

            • QTPtutorialnet

              Here is the HTML, notice how towards the top and the bottom of the code, you can see the link that is in question. It probably didn’t highlight because you either need to scroll to the right location, or the link is dynamically created as you scroll down the page, or it’s just in the html but not actually visible on the page:

              Practice Automation

              Select Page

              Automation Resources

              Practice Automation

Pin It on Pinterest

Clef two-factor authentication