Selecting an object from a dropdown menu using QTP/UFT

Hello there! Today, I will show you how to select an object from a dropdown menu quickly and easily using QTP/UFT automation. I will be using our website QTPtutorial.net as an example.

CODE:

Browser("name:=.*Learn how to use any Automation Testing Tool, correctly!").Page("title:=.*Learn how to use any Automation Testing Tool, correctly!").Link("name:=Sign Up", "Index:=0").Click


 

Use the code above and change all of the property values to fit your particular application. Or you can follow the below steps to see how I automated this process step by step.

I will be clicking on the "Sign Up" dropdown link within the "My Membership" tab

1. Go to www.qtptutorial.net

2. Activate the object spy tool in QTP/UFT and hold the "Ctrl" key while hovering over the "My Membership" menu tab.

3. Let go of the control key and click on the "Sign Up" object. I will use the title value for both the browser and the page since this is a unique property for both objects. Your code should look like the example below.

ex. Browser("title:=| Learn how to use any Automation Testing Tool, correctly!").Page("title:=| Learn how to use any Automation Testing Tool, correctly!")

4. Next, grab the Link's unique property and add an Index just in case there are two or more objects with the same property value. In this case, I will use the name:=Sign Up with an Index of 0. Your code should look like the example below.

ex. Browser("title:=| Learn how to use any Automation Testing Tool, correctly!").Page("title:=| Learn how to use any Automation Testing Tool, correctly!").Link("name:=Sign Up", "Index:=0").Click

5. When I ran the code, I received an error stating that the Browser object was not recognized. Make sure to read through the warning messages thoroughly as they usually tell you which objects are not being found by QTP/UFT. In this situation, QTP/UFT is having a hard time with the | special character located in the title for both the Browser and Page. What I usually do in this situation, is replace the special characters with a regular expression .* This expression tells QTP/UFT that as long as the Learn how to use any Automation Testing Tool, correctly! is found for the object title value, anything before this string will be accepted as well. Your code should now look like the example below.

ex. Browser("title:=.*Learn how to use any Automation Testing Tool, correctly!").Page("title:=.*Learn how to use any Automation Testing Tool, correctly!").Link("name:=Sign Up", "Index:=0").Click

Now run your code and it will click on the dropdown "Sign Up" link within the My Membership menu tab. Congrats, you are one step close to becoming an automation guru!

Pin It on Pinterest

Clef two-factor authentication