Checking if a button is disabled Java/Selenium - isEnabled() always returns true



  • I'm fighting with the following button, trying to assert that it is disabled:

    <button _ngcontent-c20 appsymbol="plus" class="btn btn-primary" type="button" disabled>
    

    button.isEnabled() returns true even though it is disabled. I know it is disabled from manually trying to click it, and because it says so in the tag. Does anyone have any idea how I can test that it is actually disabled, or test that the tag contains 'disabled'?

    I'm not trying to click the button, rather test that it is disabled because the form it belongs to has not been completed correctly.



  • You are calling is_enabled() on the click() result (None). Instead, you should first get the element, check if it is_enabled() then try the click() (if that is what you are trying to do). For example

    elem = driver.find_element_by_id("myId") if elem.is_enabled(): elem.click() else: pass # whatever logic to handle.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2