-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Java] Add visibility check to selectByVisibleText in Select class #15912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
[Java] Add visibility check to selectByVisibleText in Select class #15912
Conversation
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 SeleniumHQ#15265
Thank you, @SantiagoCecena for this code suggestion. The support packages contain example code that many users find helpful, but they do not necessarily represent We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks. |
PR Reviewer Guide 🔍(Review updated until commit b4475b0)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to b4475b0
Previous suggestionsSuggestions up to commit b4475b0
|
@SantiagoCecena please fix the formatting and update your branch (missing space after |
Also, please sign the CLA: #15912 (comment) |
User description
🔗 Related Issues
Fixes #15265
💥 What does this PR do?
This PR updates the
selectByVisibleText
method in the JavaSelect
class to prevent selecting<option>
elements that are hidden via CSS.Specifically, the method now checks for CSS properties:
display: none
visibility: hidden
opacity: 0
or0.0
An existing private method,
hasCssPropertyAndVisible
, is used to verify visibility.🔧 Implementation Notes
The fix was done by calling
assertSelectIsVisible()
at the beginning of the method, following the same pattern already used inselectByContainsVisibleText
.No new logic or dependencies were introduced, and behavior is now consistent across both selection methods.
💡 Additional Considerations
The change was manually tested in a local environment using WebDriver, since I currently cannot run Bazel locally due to company machine restrictions.
If needed, I'm happy to follow up with a Bazel-compatible test or collaborate with a maintainer to integrate one.
🔄 Types of changes
PR Type
Bug fix
Description
• Add visibility check to
selectByVisibleText
method in Java Select class• Prevent selection of hidden options with CSS properties like
display: none
• Make behavior consistent with
selectByContainsVisibleText
methodChanges walkthrough 📝
Select.java
Add visibility validation to selectByVisibleText method
java/src/org/openqa/selenium/support/ui/Select.java
• Added
assertSelectIsVisible()
call at method start• Added
visibility check for each option using
hasCssPropertyAndVisible()
•
Throw
NoSuchElementException
for invisible options with descriptivemessage