is_enabled() returns wrong state

78 views
Skip to first unread message

Johnny Lim

unread,
Feb 8, 2023, 1:22:40 AM2/8/23
to Selenium Users
An element shows that it is disabled.

<a class="paginate_button previous disabled" aria-controls="tablepress-18" data-dt-idx="0" tabindex="-1" id="tablepress-18_previous" >Previous</a>

Yet when I test it using is_enabled() , it returns True.

driver.find_element(By.XPATH,'//*[@id="tablepress-18_previous"]').is_enabled()

Any idea anyone?  Thanks a lot.

Adrian

unread,
Feb 9, 2023, 3:14:50 PM2/9/23
to Selenium Users
I don't know why is_enable() is returning true.
I would just change your xpath.

I'm guessing that when the element is enable it will look something like:
<a class="paginate_button previous" aria-controls="tablepress-18" data-dt-idx="0" tabindex="-1" id="tablepress-18_previous" >Previous</a>

So try changing your xpath to:
driver.find_element(By.XPATH,'//*[@id="tablepress-18_previous"][@class="paginate_button previous"]')

If the button is still disabled, then the find_element call will return null.

Cheers,
Adrian.

David

unread,
Feb 15, 2023, 12:12:26 AM2/15/23
to Selenium Users
Just wanted to elaborate on what you are observing.

If I'm not mistaken, adding text of "disabled" to a class name of an element does not mean the element itself is disabled. "Disabled" itself is an attribute "name" (with no value) in the HTML DOM, and is typically meant for HTML input/form elements. The element you have in question is a hyperlink, I'm not aware of hyperlinks being able to be disabled, other than javascript click-blocking code that stops you from right-clicking for example.

So really, the element in question's disabled/enabled state is managed by javascript code (of the site/app in question) by handling the disabled text in the class name, and is not actual HTML DOM disabled element handling, thus that is why the function is_enabled() returns incorrect state because that is based on the native HTML DOM approach. Basically to summarize, the site/app uses javascript to fake/mimic element disabled and not using native element disabling from the DOM. This javascript faking approach is use often these days, like fake drop down lists that aren't real HTML select list elements.

Johnny Lim

unread,
Mar 10, 2023, 12:53:31 AM3/10/23
to Selenium Users
Thanks to Adrian and David for your suggestions.
Reply all
Reply to author
Forward
0 new messages