java - 使用列表/字符串单击并下拉值
问题描述
我有一组数组值,需要使用它们单击下拉对象,如何以正确的方式执行此操作?
我的 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}] +")]"
i
的索引在哪里countries[]
(也注意countries
是小写,按照惯例)。
然后遍历列表:
for (def i=0; i<countries.size(); i++){
getMarket_selector(Market_selector(i.toString()))
}
推荐阅读
- payment-gateway - 如何实现自动充值支付流程
- css - 我如何从一个组件发送背景颜色数组并将其发送到 css 以响应本机
- android - 某些 android 设备上的应用程序崩溃并出现错误(在严格模式之外尚不支持块范围声明(let、const、函数、类)
- sql - Aggregating values of particular key in json array - PostgreSQL
- iis - IIS WorkerProcess CPU 峰值导致服务器无响应
- django - Django如何在基于类的视图分页中传递用户对象?
- flutter - 如何将参数传递给flutter integration_test?
- r - tibble 数据帧中原子向量的访问频率
- python - 将py文件编译为pyc导致程序失败
- hive - 在 Streamsets DC 中读取 hive 表(或 parquet 格式的 HDFS 数据)