WebElement Object Recognition Issues
Assistance with Quick Test Professional WebElement Object Recognition issues is one of the most-asked questions I receive.
It's mostly due to the reasons I list in my 6 Things to Try When QTP Does Not Recognize an Object post; other times the issue is that people are having a hard time interacting with a web element – for instance, trying to enter text into a web element without any luck.
Although it can be frustrating at times to obtain the behavior you want, you can actually use the .object method of QTP to get around most interaction issues.
WebElement Frustration
Recently I received an email from a frustrated user. They wrote:
“Here is a sample problem I am running into:
- go to Boostmobile.com
- select Shop/Phones from the menu
- add any phone to the cart
- enter a zip code and click check availability
We have now arrived at a place where the problem is: How would one make that State drop down select a state?”
Using the object method along with descriptive programming will allow us to get around this issue.
How to enter text into a WebElement
- First, start QTP up and manually follow the steps above to get to the state web element that we're going to work with in the following example.
- Click “record” on QTP, select a state from the dropdown and stop recording.
- Notice how only the click action is recorded, without any information on what state was selected:
Browser("Checkout Step 1 | Shipping/Bil").Page("Checkout Step 1 | Shipping/Bil").Link("State").Click
- Next, point the QTP spy on the state field.
The “State” field is identified as a webelement. (This kind of stinks, because if you look at the help for the methods of a webelement, there are no available methods for entering or selecting text.)
WebElement Methods
Method Name | Method Desc |
CaptureBitmap | Saves a screen capture of the object as a .png or .bmp image, depending on the specified file extension. |
Check | Checks whether the actual value of an item matches the expected value. |
CheckProperty | Checks whether the specified object property achieves the specified value within the specified timeout. |
ChildObjects | Returns the collection of child objects contained within the object. |
Click | Clicks the object. |
Drag | Performs the ‘drag' part of a drag and drop operation. |
Drop | Performs the ‘drop' part of a drag and drop operation. |
FireEvent | Triggers an event. |
GetROProperty | Returns the current value of the specified identification property from the object in the application. |
GetTOProperties | Returns the collection of properties and values used to identify the object. |
GetTOProperty | Returns the value of the specified identification property from the test object description |
MiddleClick | Middle-clicks the object. |
Output | Retrieves the current value of an item and stores it in a specified location. |
RefreshObject | Instructs QuickTest to re-identify the object in the application the next time a step refers to this object. |
RightClick | Right-clicks the object. |
SetTOProperty | Sets the value of the specified identification property in the test object description. |
Submit | Submits a form. |
ToString | Returns a string that represents the current test object. |
WaitProperty | Waits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next step. |
Now what? Actually, we're in luck; we can use the webelements object method along with descriptive programming to access and interact with the native methods and properties of a webelement.
WebElement Object Property with Descriptive Programming
To select a state — Rhode Island, for instance — we can use the innertext property to select the value in the State webelement as follows:
Browser("Checkout Step 1 | Shipping/Bil").Page("Checkout Step 1 | Shipping/Bil").Link("html tag:=A","index:=1").WebElement("html tag:=SPAN").Object.innertext = "Rhode Island"
Using descriptive programming allows us to bypass the object repository and use the property/value in place of an OR name. Using the innertext property of the web element allows us to set the State name we want to use.
This should give us enough functionality to move on in our scripting.
Pretty cool!
Nice on Joe ….this will save time instead of running a loop and matching with the innertext :-)
Please also add as to how to enter text in WebElement object. I have to enter quantity instead of selecting. Would innertext work
like
object.innertext = “1”
Please advise. Thanks
Thank you so much, i’m looking for this thing 2 days ago.
Thank u.
Saad Zaidani » Great!
Appreciated.
Kevin
Thanks Kevin!
Hi Joe,
I am facing an issue.I have recorded a script in qtp 11 in IE 9 browser.
my script has two drop downs, country and state.
When i select country, values in ‘state’ drop down updates accordingly. it is working fine manually but when i record the script and run then on selecting country from country drop down, state drop down doesn’t update and shows no values. hence script shows error .
Please suggest any solution for this problem asap.
This might sound like odd suggestion but after you select the value what happens if you add a tab off? I’ve tested application that If I did not tap out of a field the values would not change.
I have a strange issue with the above method when I change the innertext and then perform remaining actions in my case I select dropdown selection (change innertext) and then press submit button. The result takes in whatever the default selection in the dropdown list was and then queries it. For example if the DDL(webelement) had selection ‘A’ in it when I do the innertext to ‘B’ and then do the search. It still gets tme the result for ‘A’. I would appreciate if you have any work around for this. The application is HTML5 C#.Net application
Hi,
I am facing an issue, where I need to enter text in webelement. It is kind of text box. Is there is any function for doing this?
So does this not work for you? What happens?
Hi Joe, I think the issue resolves for one WebElement in the page, but i have 5 more webelements in the same page and qtp sends me a meesage “objects description matches more than one of the objects currently displayed in you application….”, how can i identify the webelement to eidt?
Thanks for your help
Hi Adrian – can you specify the index:= for each one to make them unique so that you don’t get this message?
Kindly, specify a solution on how to resolve if the same kind of problem arises with a desktop application
I am running into the same issue as Kiran where I can see the value I need in the WebElement, but when I click ‘Submit’ or ‘Save’ the application is somehow not seeing the value. My example is for a State field. I use Object.innertext = “Michigan”, and can see the value get populated in the WebElement, but when I click ‘Save’ I am receiving a ‘State is required’ message since it’s a required field.
I have a strange issue with the above method when I change the innertext and then perform remaining actions in my case I select dropdown selection (change innertext) and then press submit button. The result takes in whatever the default selection in the dropdown list was and then queries it. For example if the DDL(webelement) had selection ‘A’ in it when I do the innertext to ‘B’ and then do the search. It still gets tme the result for ‘A’. I would appreciate if you have any work around for this
Hi All,
I am facing a issue, when a drop down is identified as a webelement, if I need to verify the dropdown values in the dropdown. How this can be done .Please help me…..
Hi,
I’m facing a problem where I need to enter a string value in webelement and then click on next button but when I used Object.innertext = “Text” with webelement its just print the Test and next button disappear . I want to go to next page after entering the Text and clicking next.Please help.
Hi Joe,
I am trying to automate a page for my firm but am running into an issue.
The page has a webedit in which i enter text, this then displays a webelement box with matching results. It records fine, but when i run the same the webelement does not appear (it will if i manually edit the editbox).
I need to be able to view the values in the weblement box and then select one. i have tried adding synchronization, using the object.innertext methods, but it doesnt work. each time the script runs, it will enter the text in the box, but the webelement does not appear.
Any help is appreciated!!!
thanks