Skip to content

Commit b4475b0

Browse files
Add visibility check to selectByVisibleText in Select class
This change updates the selectByVisibleText method to prevent selecting <option> elements that are hidden via CSS properties: "display: none", "visibility: hidden", and "opacity: 0" or "0.0". It uses the existing hasCssPropertyAndVisible method to ensure that only visible options can be selected, making this method consistent with selectByContainsVisibleText, which already has this behavior. Fixes #15265
1 parent 9318b7a commit b4475b0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

java/src/org/openqa/selenium/support/ui/Select.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,16 @@ public WebElement getFirstSelectedOption() {
123123
@Override
124124
public void selectByVisibleText(String text) {
125125
assertSelectIsEnabled();
126-
126+
assertSelectIsVisible();
127127
// try to find the option via XPATH ...
128128
List<WebElement> options =
129129
element.findElements(
130130
By.xpath(".//option[normalize-space(.) = " + Quotes.escape(text) + "]"));
131131

132132
for (WebElement option : options) {
133+
if(!hasCssPropertyAndVisible(option)) {
134+
throw new NoSuchElementException("Invisible option with text: " + text);
135+
}
133136
setSelected(option, true);
134137
if (!isMultiple()) {
135138
return;

0 commit comments

Comments
 (0)