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).
For example:
<option value="0" label="not-intresting">VERY-LONG-TEXT-THAT-I-NEED-TO-SELECT-DOLLAR</option>
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
Eventually I combined the answers here and that's the result:
And in Scala (need it eventually in Scala) it looks like:
My solution is to use xpath to find options that are children of the select. Any xpath method can be used to find the select; in this example I am finding the select by id.
After a little more thought I realize the option can be found entirely with xpath:
Using Java 8 Stream/Lambda:
This is what I used to solve the issue in python.
I used this option, so it selects the text that uses the word
DOLLAR
instead of typing the whole word as the value.instead of
Get a list of all the
option
values and then check if the value contains your partial text. Something like this: