Automation Testing

QTP Secret on How to Enter Text in a WebElement

By Test Guild
  • Share:
Join the Guild for FREE

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!

 

  1. 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

  2. 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.

  3. 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.

  4. 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

  5. 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?

  6. 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

  7. Kindly, specify a solution on how to resolve if the same kind of problem arises with a desktop application

  8. 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

  9. 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…..

  10. 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.

  11. 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

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Leveraging AI and Playwright for Test Case Generation

Posted on 11/22/2024

Two BIG trends the past few years in the software testing space been ...

Symbolic AI vs. Gen AI: The Dynamic Duo in Test Automation

Posted on 09/23/2024

You've probably been having conversations lately about whether to use AI for testing. ...

8 Special Ops Principles for Automation Testing

Posted on 08/01/2024

I recently had a conversation, with Alex “ZAP” Chernyak about his journey to ...

Sponsor The Industry-Standard E2E Automation Testing Annual Online Event (Limited Spots Left) - Reach Out Now >>