[英]How do I select option from a Select Listbox dynamically during runtime ? Selenium_Java
I have a select listBox of around 10 elements containing account no.我有一个包含帐户号的大约 10 个元素的选择列表框。 with balance.
与平衡。 These balances change sometimes they go to zero some time they have some amount, what i want to do is select the option at runtime which has positive account balance.
这些余额有时会发生变化,有时会在有一定金额时变为零,我想要做的是在运行时选择具有正帐户余额的选项。 Format of the text in LB is : Acc no.
LB 中的文本格式为:Acc no. (INR 12345 :SomeText)
(INR 12345 :SomeText)
Thanks in advance.提前致谢。
load select option加载选择选项
get select option xpath获取选择选项 xpath
then get all the text reside in the option element然后让所有文本驻留在选项元素中
Then you logic那你逻辑
List<WebElement> allOptions = driver.findElements(optionXpath); List<String> optionHasMoreMoney = new ArrayList<String>(); for(WebElement eachEle: allOptions){ long amount = Long.parseLong(eachEle.getText()); if(amount > 0){ optionHasMoreMoney.add(eachEle.getText()); } } // list of options which has more money Select select = new Select("your select element"); select.selectByValue(optionHasMoreMoney.get(0));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.