I have a select listBox of around 10 elements containing account no. 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 a positive account balance. The format of the text in LB is : Acc no. (INR 12345 :SomeText)
Thanks in advance.
CodePudding user response:
load select option
get select option 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));