单击并使用 list/string 下拉值

Click and Drop down values by using list/string

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

我的 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()))
}