Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Want to Automate clicking on Menu items
08-31-2010, 06:33 PM
Post: #1
Want to Automate clicking on Menu items

Hi

I am Automating an ASP.Net application having teleric control with QTP 9.2. I am creating a generic keyword driven framework. I am able to successfully Login with my framework. Now i want to click on Menu items that i am able to do after that i want to click on menu items under it with same click function.I am able to do that if i pass only index of menu items but if i pass html tag and text as property it fails, as index is not a good option to work with, can anyone tell me what approach i should opt.


Just to tell, i have recorded click on menu item and run that it worked but when i use DP there for the object and taken text and html tag as property it failed.may with recording it is using other properties as well to identify the object.but it is hard to try with all combination of properties for many objects.

if there is any approach to click that by using DP then i can easily automate that in my framework.Can anyone help me to automate this issue.

You can assume the Menu items like this:

Name
.Ram
.Shayam
Age
.21
.25


Thankx
Find all posts by this user
Quote this message in a reply
09-02-2010, 10:22 PM
Post: #2
RE: Want to Automate clicking on Menu items
It's been my experience that the only reliable way to get DP to work with multiple criteria is to use a Description object array.

Code:
dim objdescription, myobj, linkarray
   set objdescription = Description.Create()
   objdescription("text").value = "Click Me"
   objdescription("html tag").value = "a"
   objdescription("html tag").RegularExpression = false
   objdescription("micclass").value = "Link"
   Set myobj = Browser("Browser").Page("Page")
   myobj.sync
   set linkarray = myobj.ChildObjects(objdescription)
   linkarray(0).Click

This should get you started. You can make it dynamic by passing in text and tag parameters. If there is more than one you can add other values to the array such as html id. I took this code a made a click function that will take my ID or Text parameter and search for any clickable object (link, button, image, etc) by changing the micclass if my linkarray object length is "0". You can also use regular expressions.

Thanks
Find all posts by this user
Quote this message in a reply
09-03-2010, 10:34 AM (This post was last modified: 09-03-2010 02:50 PM by Manan.)
Post: #3
RE: Want to Automate clicking on Menu items
(09-02-2010 10:22 PM)jsknight1969 Wrote:  It's been my experience that the only reliable way to get DP to work with multiple criteria is to use a Description object array.

Code:
dim objdescription, myobj, linkarray
   set objdescription = Description.Create()
   objdescription("text").value = "Click Me"
   objdescription("html tag").value = "a"
   objdescription("html tag").RegularExpression = false
   objdescription("micclass").value = "Link"
   Set myobj = Browser("Browser").Page("Page")
   myobj.sync
   set linkarray = myobj.ChildObjects(objdescription)
   linkarray(0).Click

This should get you started. You can make it dynamic by passing in text and tag parameters. If there is more than one you can add other values to the array such as html id. I took this code a made a click function that will take my ID or Text parameter and search for any clickable object (link, button, image, etc) by changing the micclass if my linkarray object length is "0". You can also use regular expressions.

Thanks for that, but i used that approach only to click on objects and it is working fine for me for other objects but for some it is not working.

Please clarify few thing:

Scenario 1:
Before recording i set the Options in Object Identification window as Web--->Links----> Html tag, text, index and when i recorded that it recorded the value as: A,Add,none when i run that it clicked. but when i use DP with that parameters it failed. Then i thought to add more properties in O.R and clicked on add button i realized that value for other properties are already recorded by QTP although i have set only 3 parameters from Object identification window.

Is this possible that QTP is using combination from those properties as well to click on that object and i m using only html tag, text and index that is why it is failing. Please clear this.


Scenario 2:
When i set only ordinal identifier in object identification window for web--> link and recorded the click event on that object then it showed me its index value as 6 and no other property as i have set only index option in object identification.

and when i done DP only with index value it clicked. but when i used index value with other properties like text in DP it failed again.


I have taken Text,Html Tag, index as properties for all links and i want it to be consistent otherwise i have to take some properties for one link and others for other links.Objects for which it showed None after spying as ordinal identifier i used index as 0 for those.Please help me.

Just to know is there any way by which At run time i can verify the object below and object after, the object under test so that always right object is identified at run time.

Thanx
Find all posts by this user
Quote this message in a reply
09-08-2010, 08:10 PM (This post was last modified: 09-08-2010 08:44 PM by jsknight1969.)
Post: #4
RE: Want to Automate clicking on Menu items
I'll try to clarify.

First using DP ignores the OR, but I'm sure you knew that.

When using DP, you must be very specific in your object to get only one object. You might try using HTML ID instead of Text. If you have a dozen links on a page that all have the text of "Edit", they will all be returned in the child objects and you can use the index key to get the one you want.
Code:
linkarray(0).Click

That is what this did. You can change the "0" to the index option you need. When you use a .NET Grid or List object that is the only way to click the correct link in the data. There are ways to search the table for the row you need, provided there is a unique key or data, then use that as the array index as well.

In my click framework, I pass the index with a default of "0" so at the very least it will click the first object in the array.

Be sure you are setting your micclass. Also, try using Regular expressions to search for the text of the link. That might help narrow down the objects array so you won't have to deal with the indexing.

I hope this helps.
I don't think I explained that very well, so I decided to share my framework. I'm sure there is a lot of room for improvement but it suits my needs and makes it very simple for my team to reuse the code.

There are some page/browser variables you need to set at the top of the code to work with the website you are working with. After that it the framework should work fine. I generally include another library setting those values, but for this upload it's all one file.

Documentation is always a work in progress for me, so I apologize if it's a little lax in some areas.

I hope you find this useful.


Attached File(s)
.txt  webframework.txt (Size: 24.41 KB / Downloads: 20)

Thanks
Find all posts by this user
Quote this message in a reply
09-09-2010, 09:16 AM
Post: #5
RE: Want to Automate clicking on Menu items
Thanks for that, i resolved that issue in my click function as i am taking text property and in that i have done one silly mistake i have not make regular expression false, and the text property is having special symbol in it, due to which it was failing.

Yesterday i automated Ajax for my application, and i am very much successful in that but at one case there is a problem as, while the ajax is going on a pop up appears, now qtp is in ajax function waiting to complete but it will not set its status as complete until i pop up is clicked. What i thought is to use timer as well in condition that if the status is not complete then it should wait for that particular seconds in ajax function.

Don't you think with this my scripts will fail if application responds slowly as ajax will not be complete within that time limit.Is there any other best possible approach for that.

I will go through your code today and tree to use the approach where i require. Thanks for helping me.

I am facing one more issue with my Function named verifytextonpage in that i am taking all child objects on page and then i iterate all child objects innertext property to find my string with help of INSTR function but the problem is that the function is slow as it has to iterate no. of times to find the string. Is there is any other way to to that.

I appreciate your help, Thanks once again!
Find all posts by this user
Quote this message in a reply
09-09-2010, 08:29 PM
Post: #6
RE: Want to Automate clicking on Menu items
In my framework, I have a search page for text function that uses the page innertext and a INSTR function. It doesn't really care about objects, just text and is a lot faster than the childobject method. It might suit your needs.

AJAX can be tough because the html objects don't exist until later. Try doing a page.sync then a search and click on the object you need. That might work. I know in QTP10 there is a new dev application called the Web Extensibility that is suppose to be able to test ajax, but I haven't used it much and it probably won't work well with 9.2. Best bet is going to be the sync then click. It depends on how the popup is coded. If it's a hidden div that just becomes visible, QTP can find it. If it's a javascript function that builds and adds HTML it might be more difficult, but I still think QTP will find it if you use the right object. Try my click framework, see if it works.

Thanks
Find all posts by this user
Quote this message in a reply
09-16-2010, 10:31 AM
Post: #7
RE: Want to Automate clicking on Menu items
I Automated Ajax in my framework, i have seen the text search in your file and that worked for me. Thankx for it.
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Problem in selecting multiple items in the weblist vijay44 7 1,503 08-10-2011 06:22 PM
Last Post: gaveyom
  How to check for duplicate rows/items in table? Aestival 10 1,935 02-25-2011 10:31 AM
Last Post: chandrashekhar_g
Exclamation QTP not clicking on Child window button nistalaramesh 0 1,114 12-06-2010 06:55 PM
Last Post: nistalaramesh
  Test unable to record this step: clicking the first row out of various search results hima 10 1,226 08-25-2010 07:40 PM
Last Post: supputuri
  Need info in selecting menu items in word document Ram2009 0 429 06-08-2010 05:19 PM
Last Post: Ram2009

Forum Jump:


User(s) browsing this thread: 1 Guest(s)