Selenium Select - 选择部分文本的下拉选项 [英] Selenium Select - Selecting dropdown option by part of the text
本文介绍了Selenium Select - 选择部分文本的下拉选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Selenium选择有3种不同选项选择的方法:
The class Selenium Select has 3 methods of different option selection:
- selectByIndex
- selectByValue
- selectByVisibleText
现在,我想要通过某些文本选择一个选项部分出现在其中一个选项可见文本中(不想让自己暴露于整个文本中的更改)。
Now, I have a situation where I want to select an option by some text that partially appear in one of the options visible text (don't want to expose myself to changes in the WHOLE text).
例如:
<option value="0" label="not-intresting">VERY-LONG-TEXT-THAT-I-NEED-TO-SELECT-DOLLAR</option>
我想通过提供DOLLAR来选择此选项,例如:
And i want to select this option only by providing the "DOLLAR", something like:
select.selectByPartOfVisibleText("DOLLAR")
你会如何有效地实现它?
How would you implement it effectively?
推荐答案
你可以尝试这样的逻辑希望这会有所帮助
You can try a logic like this hope this helps
List <WebElements> optionsInnerText= driver.findElements(By.tagName("option"));
for(WebElement text: optionsInnerText){
String textContent = text.getAttribute("textContent");
if(textContent.toLowerCase.contains(expectedText.toLowerCase))
select.selectByPartOfVisibleText(expectedText);
}
这篇关于Selenium Select - 选择部分文本的下拉选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文