-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[🚀 Feature]: Methods Select.select*()
should NOT allow selecting DISABLED option (or select)
#10812
Comments
@asolntsev, thank you for creating this issue. We will troubleshoot it as soon as we can. Info for maintainersTriage this issue by using labels.
If information is missing, add a helpful comment and then
If the issue is a question, add the
If the issue is valid but there is no time to troubleshoot it, consider adding the
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable
After troubleshooting the issue, please add the Thank you! |
Is this something you see in all browsers or in an specific browser? I am probably wrong, but I was reading the WebDriver spec and in 14.1 (https://www.w3.org/TR/webdriver1/#element-click), step 7 talks about
But I assume it talks about the whole element, not the specific options. I just want to understand better the problem, and figure out if this needs a fix in Selenium or in the WebDriver spec. @titusfortner @AutomatedTester @jimevans what do you think? |
@diemol I am not sure about the spec, but in reality both
|
No, Selenium should not prevent a user from clicking anything they want. A disabled element could theoretically have any number of JS event listeners. That's why the spec allows all the other actions to be taken on a disabled option element except for the part about changing "selectedness". The driver is doing the right thing and Selenium is doing the right thing. |
Watir, on the other hand, does prevent this, because as a tester, 99% of the time trying to select something that is disabled is wrong, so we've added extra logic to raise an error for it. @asolntsev we discussed this a couple years ago about why Watir subclasses elements. This is a good use case. Watir automatically waits for an element to be enabled if it is one of |
Hmm, to argue with myself a second, this *is in an opinionated class. The intention of "select" is different from the intention of "click" even if that is the implementation detail happening below. |
This is one of those weird places where Selenium tries to have it both ways. It's "just browser automation" (aka "do what I say"), except it also has these support classes to provide "do what I mean" behaviors, but only in some cases, and not implemented in a way that can really be uniformly applied throughout a test framework. |
Ok, I've convinced myself that this is should be considered a bug for this class as written. But as @pujagani pointed out in the PR, this isn't just a Java issue. |
This is a good question how the library should behave. :) I made a small experiment.
In both cases, Selenium behaves differently from real browser/user: Select select = new Select($("#frozen"));
select.selectByVisibleText("Anna"); // does NOT fail, looks like succeeded
select.getFirstSelectedOptions(); // returns ANOTHER option (the first empty option) While the end-users cannot select any options at all. |
One thing I am still missing is if this behavior is present in just one browser or in all of them. Which browsers have you tried? |
I believe all browsers are doing the right thing according to the spec. The issue is only whether Selenium should be more opinionated in this support class implementation, and I think @asolntsev makes a good case for it. The user should be allowed to "click" a disabled option element and the browsers will do what the spec tells them to without error. If the user wants to "select" an option via the higher level Select class, though, that method should error if the option is not in a state that can be selected. The current implementation just executes the click which, per the spec, doesn't change "selectedness." If the intent is to select, Selenium should error. |
Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
So I'm looking through this in the Ruby bindings, and it brings up a bunch of weird edge cases... Should I also don't think any of these methods should work for a disabled Select list, which probably means putting the disabled check in the constructor. @asolntsev thoughts? |
@titusfortner Hi. I would say that
But if the whole |
Ruby - f207270 @harsha509 needs to help me with the JS, because what I'm doing isn't working. :) |
landed in JS with pr #11029! Closing as implemented in all language bindings! |
Good day @asolntsev and @titusfortner, I am using python bindings and these changes broke our tests. Please write about such changes in the changelog of all affected languages. It took me some time to figure out that the Select class was updated since nothing is written about it in the changelog. Our use-case is simple, if the Select is disabled, it should have a default option selected. We check that the proper option is selected by default. As @asolntsev have written "Yes, getOptions() should include disabled options. Users might want to check that some of them are disabled and some no." I think it's a totally valid case to check what option is selected in the disabled mode. The problem is that in Python the change was added inside the constructor. There is no way to check the options, because I cannot initiate an object.
|
@titusfortner Seems reasonable, I suggest registering a bug in python bindings. |
@titusfortner, @asolntsev I have a variant of the problem noted by @volnoboy-broadcom; I just want to examine the value of a disabled <select>, and the NotImplementedError("Select element is disabled and may not be used.") in the constructor prevents this. I too would like this part of 0eb286a of reverted/redone. |
This class is for selecting elements. You don't need it to get values.
|
@titusfortner yes and no. :)
I don't see any reasons why cannot user check those, e.g. |
That's the point, though. This class is opinionated and is a shortcut for working with Select objects in a specific way. If the object is not enabled you literally can't work with it, so it doesn't make sense to support that functionality with this class. We provide the normal classes for working with elements, including select and option elements in an unopinionated fashion where you can query information. This is literally the conversation I've been having about how Selenium is different from Cypress/Playwright and that "Selenium isn't a testing tool" because the classes that aren't in Support package are not opinionated. If you want different opinions from what is in the Select class, then build your own opinionated classes based on what is available in Selenium. |
Being a bit picky here but I think @ShaheedHaque raises some good points within
my emphasis on what I see starts to become a core question. |
I discussed with @symonk about using Support package classes are optional/additional/add-on/informational/suggestions. It is not core functionality; it is wrappers of core functionality, designed to show people what is possible not to be objective truth. There is nothing special about its implementation compared to any other implementation other than being distributed by Selenium. If anyone doesn't like the implementation provided, please please copy/paste this free and open code and make one that works better for you. I'm a little cavalier with this because I'd almost prefer to delete these classes entirely than maintain them; they are straddling the line of what Selenium has decided to be and not to be, and maintaining them just adds confusion about Selenium's intentions. Of course @ShaheedHaque raises some good points, but the scenario being discussed is not what this class was designed for, and choosing to support it is just as arbitrary as choosing to prevent people from using the class in an invalid state. All of these are "opinions" in the way I'm speaking of them. There are multiple scenarios (e.g., select element is then isn't enabled) and different ways to handle each and tradeoffs for each choice. No one implementation can be correct and performant for every possible scenario. So, because this is a class in the Support package we pick one. The one we picked recently is slightly different than the one we picked before because I think it better represents what Selenium should be doing with the Support classes relative to its core classes. That said, I'll bring this up at the next TLC meeting in case the rest of the team disagrees with me. |
@titusfortner I would ask a practical question: what problem you are trying to solve by moving the disableness to Both are not users' problems. If the change doesn't solve any real problems, is it a good change? |
Yes, I'm making a point about what Support classes are designed to be. It sounds like Selenide uses these classes directly instead of having its own implementation, though? |
Yes, currently Selenide uses few classes from |
Let's discuss at next TLC meeting (Thursday 5pm your time, I think, in selenium-tlc slack channel). |
I think it makes perfect sense for This change broke our tests, because we use
|
We agreed at the TLC meeting to restore this functionality for now. If we decide to make this change in the future, we'll mark it as deprecated first. |
Thanks, much appreciated. |
Having many scenarios which was working fine in 4.3.0. But after upgrading to 4.5.0 scenarios are getting failed. Main reason is in the latest version of selenium Select class methods is checking weather element is enable or not. I am not sure what is the purpose of adding the addition check for the element enable. |
@DhavalAtriTR This is slated to be reverted/restored, see a few messages above. |
@Wolfe1 I hope that not the whole change will be reverted, but only a small part of it.
|
@asolntsev I am not sure what exactly the plan is but I would voice concerns on #11124 if it doesn't look correct. |
@Wolfe1 Thanks for the link. Yes, it's good commit (according to my criterias). As a result, you will be able to call |
@asolntsev Yesterday I was going through upgrading to latest version of Selenide (v6.9.0), and encountered the String supposedlyTheTextFromSelect = $("select[name=nameOfDisabledSelect]").text(); // threw UnsupportedOperationException I managed to fix this by altering the code in the following way: String textOfSelectedOption = $("select[name=nameOfDisabledSelect]").getSelectedOption().text(); // works fine Which, in a way, make sense, since the |
revert was merged |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Feature and motivation
Currently
Select
methods work even theoption
is disabled. Orselect
is disabled.I suggest these
selectByFoo
methods should throw an exception.Usage example
Pull request
see #10814
The text was updated successfully, but these errors were encountered: