简体   繁体   English

如何在运行时动态地从选择列表框中选择选项? 硒_Java

[英]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.提前致谢。

  1. load select option加载选择选项

  2. get select option xpath获取选择选项 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));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Java中使用Selenium的下拉列表框中select选项首选国家/地区网站? - How to select the option preferred country/region website from the dropdown listbox within using Selenium in Java? 如何在Selenium-java中选择在运行时生成div [i]的复选框? - How to select check box which generate div[i] during runtime in selenium-java? 如何使用Java在Selenium中选择一个窗口? - How do I select a window in Selenium with Java? 如何选择一个选项<li>在java中使用Selenium Webdriver标记? - How do I select an option inside an <li> tag using Selenium Webdriver in java? 硒,从列表框中选择值,而不使用Java中的select - Selenium, select value from listbox without using select in Java 我想使用 Maven 和 paulhammant (Selenium_java) 在 textefield 中写入 - i want to write in textefield using Maven and paulhammant (Selenium_java) 如何使用Selenium和Java从自动建议中选择一个选项? - How to select an option from auto suggestions using Selenium and Java? 如何使用 selenium webdriver 和 Java 从剑道下拉菜单中选择一个选项 - How to select an option from the kendo dropdown using selenium webdriver and Java 如何根据Selenium和Java的HTML从下拉菜单中选择一个选项 - How to select an option from the dropdown as per the HTML through Selenium and Java 当相应的下拉列表不是“多选”/ java和Selenium时,如何从下拉列表中取消选择一个选项 - How can i deselect an option from a dropdown, when that respective dropdown is not a “multi-select” / java & Selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM