Dynamic Web elements
I'm new to QTP.. currently i'm trying to play a script that has a dynamic web elements, the value of the element keeps changing each time a new user logs in or is accessed. So the script that i wrote earlier fails when I used another user since the script web element has a different attribute/name/value than the one that is currently being used by the applications.. The action required for this web element is 'click' so how do i capture this dynamic web element and still perform the click action with every new value....... I thought about GetROpropety but how will i perform the click action using the getROproperty if am suppose to use it..
I know this might be simple to someone who has great QTP experience because i figure you encounter this alot but i'm new and learning..
I know there other who might not want to help but pick on my job.. with questions like "why isnt your company paying for your training etc" .. the answers is ..My employer doesnt require me to learn or know QTP.. this is a personal initiative to learn something new
Thank you for your response
Joel what controls the value you are trying to click, is it something that can be deduced or calculated?
For example if you are clicking a link that contains todays date you could build the identifying property using todays date so it will function correctly tomorrow, something like:
Browser("micClass:=Browser").Page("micClass:=Page" ).Link("innerText:=" & Date).Click
Is this something that would help resolve your issue?
Let's assume that you have your object name as "ItemNumber" asn value of this is changing every now and then. You can go for descriptive object
Set objItemNum = Description.CreateObject
objItemNum("micClass").Value = "Link" (Or"WebElement - Object Sply and Check")
objItemNum("htmlId").Value = "XXXXXX" ( Check if you have any Html Id)
Above two should be sufficient, if not then add below,
objItemNum("index").Value = 0 (1,2,3)
objItemNum("innerText").RegularExpression = True
objItemNum("innerText").Value = ".*abc.*" (only constant part)
Ashu2618.. Thank you for your help.........this is what I have following your instructions
Set objItemNum = Description.Create
objItemNum("micClass").Value = "WebElement - Member Number"
objItemNum("innerText").RegularExpression = True
objItemNum("innerText").Value = "8313942"
The value 8313942 is what keeps changing when a new user ID is used.. So when i tried what you has suggested.. the part you suggested runs ok but when it get to the scrip where the dynamic webelement is located it stops because objItemNum is not in the object repository
here is my script that fails (the part that fails)
browser("XXXPortal").Page("XXXRPortal").Frame("act ionIFrame").WebTable("User ID").WebTable("User ID_2").webelement("objItemNum").Click
here the object spy details of the web element
Class Name: Web Element
class: tdLeftStyle LVHighlightRow
height : 18
html id: (no value here)
html tag: TD
innerhtml: 8313942 <INPUT id=pyWorkPartyUri1 value=8313942 type=hidden name=$PMemberSearch$ppxResults$l1$ppyWorkPartyUri>
outerhtml: <TD class="tdLeftStyle LVHighlightRow" width=100>8313942 <INPUT id=pyWorkPartyUri1 value=8313942 type=hidden name=$PMemberSearch$ppxResults$l1$ppyWorkPartyUri> </TD>
type : (no value here)
Well done on supplying the Object Spy output by the way, it makes helping very easy
You probably just took Ashu a little bit too literally by using the innerHTML he suggested in his example. With the object spy you should be able to find unique descriptors that can be used to find the object by QTP. The key is to ensure that those descriptors will function time and again and with your example properties provided it should be easy to identify from user to user which properties change and which ones don't.
The member number that changes should never be used in describing the object, but you have some others that seem useful (type & name).
Then to use the description when required:
Set oDesc = Description.Create
oDesc("name").RegularExpression = True
oDesc("name").Value = ".*MemberSearch.*Results.*WorkPartyUri.*"
oDesc("type").RegularExpression = True
oDesc("type").Value = ".*MemberSearch.*Results.*WorkPartyUri.*"
If you wanted to actually capture the MemberNumber, not click (click seems odd on a non-link/button webelement by the way) you can try this:
Browser("XXXPortal").Page("XXXRPortal").Frame("actionIFrame").WebTable("User ID").WebTable("User ID_2").WebElement(oDesc).Click
sMemberNumber = Browser("XXXPortal").Page("XXXRPortal").Frame("actionIFrame").WebTable("User ID").WebTable("User ID_2").WebElement(oDesc).GetRoProperty("innertext")
Msgbox "The Member Number for the User is: " & sMemberNumber
While I have been working for Businesses that are Vendor partners with HP, IBM and Microsoft, my opinions and advice is my own.
The solutions provided are either sourced from my own scripting libraries or from a quick Google Search.
Well if you are referring webtable then you can use ChildItem method also, it will simplify the task.
Joel is the new user ID generated in the test or is it used to login or something similar?
If its a login then one solution would be to hold it in the datatable and parametrise the link using that.
If it's generated during the test then Michael's regex capture method would be the way to go.
Michael thank you for your help. I tried you code.. and its now making more sense since i see that you have to use a description that does not change for the web element. I also see how you describe the changing part using the wildcard but code still gave same message after the script failed on the same line. Object is not in the repository.. I thought this line "Set oDesc = Description.Create" declares the new object in the script!!!! I am looking for a way to click on this web element but the problem is the USER ID which is captured in the outertext (when the object is spied) keep changing when i change the user. This user ID is not used for logging into the application ..
Mark- I can parametrize a login and other aspect of the application that require different users to access the application.. I will have to parametrize the USER ID but as i move from one page to another this information is captured by other web objects ..like the web element am referring to.. So once i paramatrize this user Id in the beginning I will still have to get it changed with each new user once i arrive to the script line .....Browser("XXXPortal").Page("XXXRPortal").Frame ("actionIFrame").WebTable("User ID").WebTable("User ID_2").WebElement(oDesc).Click....... that performs the click action and I will still need to change it here but I get the concept where you use the object description to describe the object in the script execution and get QTP to recognize the object without having to use the user ID that keeps changing.. The problem now is.. How do i get the script to run without the "object not in the object repository error"..
There might be a simpler way.
See if this works:
First, comment out all that stuff about creating the object and the description - there's nothing wrong with it, but we might not need it. In other words, go back to your original script the way you first created it.
Next, use this line to click on your webelement:
browser("XXXPortal").Page("XXXRPortal").Frame("act ionIFrame").WebTable("User ID").WebTable("User ID_2").webelement("innerhtml:=\d* <INPUT id=pyWorkPartyUri1 value=\d* type=hidden name=\$PMemberSearch\$ppxResults\$l1\$ppyWorkParty Uri>").Click
Try that. Assuming all the browser, page, frame, and webtable stuff is correct in your OR, then this webelement recognition should work, unless the description is not unique (you have more than one webelement that can match that exact description).
"The last 10% of any software project will take 90% of the budgeted time. The first 90% will take the other 90%"