SeleniumLibrary
SeleniumLibrary copied to clipboard
Selenium 4.5.0 | NotImplementedError when attempting actions on disabled elements
For issues
Steps to reproduce the issue
Using selenium 4.5.0+
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Test Disabled Elements
Open Browser https://demos.jquerymobile.com/1.4.5/forms-disabled browser=chrome
Maximize Browser Window
${list_selection}= Get Selected List Label //select[@id='select-native-5']
List Selection Should Be //select[@id='select-native-5'] ${list_selection}
Error messages and additional information
NotImplementedError: Select element is disabled and may not be used.
This seems to be caused by a change in https://github.com/SeleniumHQ/selenium/issues/10812 (specifically https://github.com/SeleniumHQ/selenium/commit/e2bbb54153370ee56b43e7260aef5923ec826be4#diff-48418bfd0178cef4e4f71bf60506204d33e152281f0bb5a670b9295689b6e01e) and from the looks of the discussion it may not be changed unless there is good cause so I wanted to bring it up here in case there were opinions on the matter. This more than likely extends to quite a few keywords and I am not quite sure what the solution would be on the SeleniumLibrary side.
Expected behavior and actual behavior
We should be able to get the selected option regardless of whether the list is disabled or not. Using the previous selenium release (4.4.3) works just fine.
Environment
Browser: Chrome latest Browser driver: chrome latest Operating System: Windows 10 Libraries
- Robot Framework: 5.0.1
- Selenium: 4.5.0
- SeleniumLibrary: 6.0.0
- Interpreter: Python 3.9
Just to clarify, the NotImplementedError is thrown on both the Get Selected List Label
keyword and List Selection Should Be
keyword. Less of an opinionated correct behavior for this case I would want to see consistency. Interesting that I can get text or value from disabled text and input elements. I was playing around with
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Test Disabled Elements
Open Browser https://demos.jquerymobile.com/1.4.5/forms-disabled browser=chrome
Maximize Browser Window
${list_selection}= Get Selected List Label //select[@id='select-native-5']
List Selection Should Be //select[@id='select-native-5'] ${list_selection}
${value}= Get Value id:textinput-1
${text}= Get Text id:textinput-1
${value}= Get Value //select[@id='select-native-5']
${value}= Get Value id:select-native-5
${text}= Get Text //label[@for='checkbox-h-1a']
${text}= Get Text id:select-native-5
Close All Browsers
Added a comment to the thread
Since the original issue is closed, I wanted to summarise my points (https://github.com/SeleniumHQ/selenium/issues/10812#issuecomment-1270865873) here:
- Making the constructor raise an exception prevents useful functionality like
Select(element).first_selected_option.text
as per this thread. The alternative proposed in the original thread - at least in Python - is hideous in comparison. - Performing the check-for-disabled in the constructor is fragile at best. For example, what if the <select> is disabled after the constructor is called? Will the behaviour being guarded change in mysterious ways?
- I have no problem with opinionated code but breaking existing, reasonable code requires a high bar in terms of justification which I propose is missing.
I further note that for me, the suggested alternative way to write my code using the WebElement directly like this:
driver.findElement(...).find('option[selected]')
returns the zeroth <option> which - to be fair - is what the DOM in the browser thinks is selected. However, the pre 4.5.0 code:
Select(driver.findElement(...)).first_selected_option
returned the visible option. I don't see a way in Selenium to get the visible option...is there a way short of rewriting my code AND my tests?
As per https://github.com/SeleniumHQ/selenium/issues/10812 this functionality is getting restored/reverted in 4.6 so this can probably be closed.