简体   繁体   中英

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. 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. (INR 12345 :SomeText)

Thanks in advance.

  1. load select option

  2. get select option xpath

  3. then get all the text reside in the option element

  4. 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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM