如果获取JcomboBox中的每一项元素?
下面的例子取到JcomboBox中的每一项,并进行单击操作:
startApp("ClassicsJavaA");
// Frame: ClassicsCD
tree2().click(atPath("Composers->Schubert->Location(PLUS_MINUS)"));
tree2().click(atPath("Composers->Schubert->Die schone Mullerin, Op. 25"));
placeOrder().click();
//Declare variables for list
ITestDataList nameList;
ITestDataElementList nameListElements;
ITestDataElement nameListElement;
//Frame: Member Logon
nameCombo().waitForExistence();
//Available test data types: {selected=Selected List Element,
//list=List Elements}
java.util.Hashtable ht = nameCombo().getTestDataTypes();
System.out.println(ht);
//Get all elements
nameList = (ITestDataList)nameCombo().getTestData("list");
nameListElements = nameList.getElements();
int listElemCount = nameList.getElementCount();
for (int i = 0; i < listElemCount; i++)
{
nameListElement = nameListElements.getElement(i);
System.out.println(nameListElement.getElement());
// Click on each element
nameCombo().click();
nameCombo().click(atText(nameListElement.getElement().toString()));
};
// Frame: ClassicsCD
classicsJava(ANY,MAY_EXIT).close();
代码中主要是通过getTestData("list")取到JcomboBox中的所有元素,返回的集合是ItestDataList类型的,然后再通过getElements方法取到ItestDataList这种类型集合中的所有元素,放到ItestDataElementList类型的对象中存储起来,接着就可以通过getElement方法访问对象中的每个元素了。
关于ItestDataList、ItestDataElementList的描述可参考RFT的帮助文档:
All Superinterfaces:
ITestData
public interface ITestDataList
extends ITestData
Represents the elements in a list-type object for a verification-point operation. The elements in the list are encapsulated in an ordered list.
Since:
RFT1.0
Method Summary |
|
|
|
|
|
|
|
|
|
|
|
|
|
public interface ITestDataElementList
Used by the ITestDataList
interface to encapsulate the ordered set of generic elements that make up the desired list. This interface is not typically used directly, but instead is a shared implementation of a collection of generic elements without specific higher-level control attributes. When used relative to the ITestDataList
interface, appropriate comparison attributes are available to control use of the list.
Since:
RFT1.0
Method Summary |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public interface ITestDataElement
Encapsulates a generic element used in an ITestDataList
. You should not use this interface directly outside the context of a list. You can access similar functionality by directly using the ITestData
interface and specifying a property with an appropriate masking setting.
Method Summary |
|
|
|
|
|
|
|
|
|