使用列表/字符串单击并下拉值



我有一组数组值,需要使用它们单击下拉对象,如何以正确的方式执行此操作?

我的XPath"//li[@class="header__country-selector--desktop__country"]//a[contains(text()," + **ARRAY VALUES** +")]"

我的代码 :

自定义关键字:

public class selectCountry {
private String Market_selector(String nav_id){
return '//li[@class="header__country-selector--desktop__country"]//a[contains(text()," +Countries+")]'

//      //li[@class="header__country-selector--desktop__country"]//a[contains(text(),'')]
}
private TestObject getHeadernavMenuTestObject(String nav_id){
TestObject navitem = new TestObject(nav_id)
navitem.addProperty("xpath", ConditionType.EQUALS, Market_selector(nav_id), true)
return navitem
}
@Keyword
public void getMarket_selector(String nav_id){
TestObject navitem = getHeadernavMenuTestObject(nav_id);
WebUI.waitForElementPresent(navitem,GlobalVariable.load_time)
WebUI.verifyElementPresent(navitem, GlobalVariable.load_time, FailureHandling.CONTINUE_ON_FAILURE);
WebUI.focus(navitem)
WebUI.click(navitem)
}

数组

String[] Countries = ['UAE','Bahrain','Oman','Qatar','Kuwait','Egypt','Jordan','Tunisia','Morocco','Palestine','Iraq'];

你的 xpath 应该是

"//li[@class="header__country-selector--desktop__country"]//a[contains(text()," + countries[${i}] +")]"

其中icountries[]的索引(另请注意countries按照惯例是小写的(。

然后遍历列表:

for (def i=0; i<countries.size(); i++){
getMarket_selector(Market_selector(i.toString()))
}

最新更新