question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[🚀 Feature]: Methods `Select.select*()` should NOT allow selecting DISABLED option (or select)

See original GitHub issue

Feature and motivation

Currently Select methods work even the option is disabled. Or select is disabled.

I suggest these selectByFoo methods should throw an exception.

Usage example

new Select(element).selectByVisibleText("fish");

Pull request

see https://github.com/SeleniumHQ/selenium/pull/10814

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:39 (27 by maintainers)

github_iconTop GitHub Comments

5reactions
papegaaijcommented, Oct 12, 2022

I think it makes perfect sense for Select to check if the select element and its options are enabled, but only when interaction is requested on these elements. A select does have a selection when its disabled. The original request was about not being able to select disabled options, which seems like a valid request to me. The change does not implement that request. It is still possible to select disabled options, but now it is no longer possible to instantiate a Select when the select is disable at that moment. Even worse, it is now possible to operate on a disabled select, when it is disabled after instantiation of the Select. This wasn’t possible before.

This change broke our tests, because we use Select to read the selected value of a select. In some cases the element is disabled. I had to change the code like this, which is not an improvement IMHO:

- return new Select(field).getFirstSelectedOption().getAttribute("value");
+ return field.findElements(By.tagName("option"))
+     .stream()
+     .filter(WebElement::isSelected)
+     .findFirst()
+     .get()
+     .getAttribute("value");
3reactions
ShaheedHaquecommented, Oct 6, 2022

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, @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 0eb286a8fd of reverted/redone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my select option not getting disabled? - Stack Overflow
Everytime one option is selected in one box, it should be disabled in the second box. My first select box in my html...
Read more >
Select - Ant Design
Select component to select value from options. When To Use. A dropdown menu for displaying choices - an elegant alternative to the native...
Read more >
MDB Select - disabled option functionality not working
It works properly meaning the option becomes disabled when you initialize the data with disabled=true.However, I am not able to achieve that behavior ......
Read more >
react-select: An introduction - LogRocket Blog
Our react-select component follows the same convention but the options and values are passed in as props. //App.js //Import React and Select ......
Read more >
Disabling Form Controls When Working With Reactive Forms ...
You can enable/disable a form control by using the following ways: ... Let's Talk About Select and Reselect in @ngrx/store.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found