Skip to content
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

Selenium 4.5.0 | NotImplementedError when attempting actions on disabled elements #1790

Open
Wolfe1 opened this issue Oct 6, 2022 · 4 comments

Comments

@Wolfe1
Copy link

Wolfe1 commented Oct 6, 2022

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 SeleniumHQ/selenium#10812 (specifically SeleniumHQ/selenium@e2bbb54#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
@emanlove
Copy link
Member

emanlove commented Oct 7, 2022

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

@ShaheedHaque
Copy link

ShaheedHaque commented Oct 7, 2022

Since the original issue is closed, I wanted to summarise my points (SeleniumHQ/selenium#10812 (comment)) here:

  1. 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.
  2. 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?
  3. 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.

Wolfe1 added a commit to Accruent/robotframework-zoomba that referenced this issue Oct 7, 2022
* Checks in place to avoid issue with Selenium 4.5.0 robotframework/SeleniumLibrary#1790

* downgrade selenium version due to bug
@ShaheedHaque
Copy link

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?

@Wolfe1
Copy link
Author

Wolfe1 commented Oct 14, 2022

As per SeleniumHQ/selenium#10812 this functionality is getting restored/reverted in 4.6 so this can probably be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants