首页 > 解决方案 > 使用列表/字符串单击并下拉值

问题描述

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

我的 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'];

标签: javakatalon-studio

解决方案


你的 xpath 应该是

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

i的索引在哪里countries[](也注意countries是小写,按照惯例)。

然后遍历列表:

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

推荐阅读