Troubleshooting
Problem
The item text for each item in a combobox or a list box is partly dynamic. For example, the item text for a particular item is "Item 1xxxxx" where "xxxxx" is a random alphanumeric string. IBM Rational XDE Tester records Object().click(atText("Name 1xxxxx")); On playback, an unhandled exception occurs because the item text changes each time the object is created, that is, the item text changes on each playback.
Resolving The Problem
In general, the script must be edited so that it
- Retrieves all of the text from the combobox (or list box)
- Iterates through that text to find the current, run-time text of the desired item, for example, by using a regular expression to search for a matching pattern.
- Places the current (run-time) text of the selected item in a variable
- Replaces the hard-coded string in the object().click(atText("String")) with the variable, for example object().click(atText(MyVariable))
There are at least two different methods that can retrieve the text from the combobox:
- getProperty(".text")
- getTestData("list")
The getProperty method is simpler at first to use, but it retrieves the entire text of the combobox into a single string variable that must then be parsed. The getTestData method is a little more complicated, but ultimately makes it easier to evaluate the text for each item.
Below is a sample script that uses the getTestData method to retrieve the text from an HTML combobox (attached). The same code could be used with a Java combobox. It is based on the Extracting Data from a ComboBox/List Control topic in the Advanced Topics section of the XDE Tester User Guide (select Help > XDE Tester User Guide) (which can also be found by clicking on the link below). The HTML combobox itself is a list of names each followed by 5 random alphanumeric characters.
After retrieving the text for a particular item, XDE Tester assigns it to a string variable. XDE Tester then uses a regular expression in the body of the script to compare that string variable to the desired pattern (in this case, the string "Ara " followed by 5 random numeric characters). If that patten is found, XDE Tester uses the value of the string variable to click on the item in the combobox.
- ITestDataList nameList;
ITestDataElementList nameListElements;
ITestDataElement nameListElement;
//List_Names() refers to the combo box
nameList = (ITestDataList)List_Names().getTestData("list");
nameListElements = nameList.getElements();
int listElemCount = nameList.getElementCount();
for (int i = 0; i < listElemCount; i++)
{
- nameListElement = nameListElements.getElement(i);
String ClickItem = nameListElement.getElement().toString();
- Regex r = new Regex("Ara " + "[0-9]{5}");
if(r.matches(ClickItem))
{
- List_Names().click();
List_Names().click(atText(ClickItem));
break;
Note: The .text property is usually used as a recognition property for comboboxes and listboxes. Therefore, the user should also open the object map and edit the .text recognition property for the object so that the dynamic part of the text is replaced with a regular expression.
Related Information
Was this topic helpful?
Document Information
Modified date:
16 June 2018
UID
swg21192597