[rb] fix select being able to select options hidden by css rules#17037
[rb] fix select being able to select options hidden by css rules#17037FFederi wants to merge 3 commits into
Conversation
PR TypeBug fix Description
|
| Relevant files | |||
|---|---|---|---|
| Bug fix |
| ||
| Tests |
|
|
Thank you, @FFederi for this code suggestion. The support packages contain example code that many users find helpful, but they do not necessarily represent After reviewing the change, unless it is a critical fix or a feature that is needed for Selenium We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks. |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
7e9ae08 to
5422054
Compare
|
@aguspe |
@FFederi thank you for the awesome work! I just have one small comment in Java selectByVisibleText also calls assertSelectIsEnabled() and assertSelectIsVisible() on the parent select before iterating options, want to add the same here? |
Code Review by Qodo
Context used 1. Missing Set require
|
| module WebDriver | ||
| module Support | ||
| class Select | ||
| HIDDEN_CSS_VALUES = %w[hidden none 0 0.0].to_set.freeze |
There was a problem hiding this comment.
1. Missing set require 🐞 Bug ☼ Reliability
Select initializes HIDDEN_CSS_VALUES using .to_set during file load, but the codebase does not require Ruby’s stdlib set, so loading this file can raise NoMethodError for to_set. This is a new hard-failure path because the constant is evaluated immediately when the file is required.
Agent Prompt
### Issue description
`rb/lib/selenium/webdriver/support/select.rb` now calls `.to_set` while defining `HIDDEN_CSS_VALUES`. In Ruby, `Enumerable#to_set` is defined by the stdlib `set` and is not available unless `set` has been required, so loading this file can raise `NoMethodError` at require-time.
### Issue Context
This is particularly risky because the `.to_set` call happens during constant initialization (file load), so it can break any consumer that loads `Selenium::WebDriver::Support` / `Select` without having previously loaded `set`.
### Fix Focus Areas
- rb/lib/selenium/webdriver/support/select.rb[20-26]
- rb/lib/selenium/webdriver.rb[20-30]
### Suggested fix
Add `require 'set'` either:
1) locally at the top of `rb/lib/selenium/webdriver/support/select.rb`, or
2) centrally in `rb/lib/selenium/webdriver.rb` (preferred if you want to support other existing `.to_set` usages across the library).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
🔗 Related Issues
Related to issue: [🚀 Feature]: Unifying Select Class Across All Bindings
💥 What does this PR do?
Modifies select behaviour to make it the same as python and Java bindings.
In particular, makes it so selecting an option hidden by CSS rules raises an exception.
🔧 Implementation Notes
I couldn't find (or understand) a general way to check visibility of an element, so I added a simple check on CSS values like it's been done with Java and python.
🔄 Types of changes