The Python Oracle

Using Selenium and Python, how to check whether the button is still clickable?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5 Looping

--

Chapters
00:00 Using Selenium And Python, How To Check Whether The Button Is Still Clickable?
00:50 Answer 1 Score 4
01:06 Accepted Answer Score 6
02:03 Thank you

--

Full question
https://stackoverflow.com/questions/3069...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #selenium #webscraping

#avk47



ACCEPTED ANSWER

Score 6


Without knowing more about your example target, the minimal that can be said is that a clickable attribute would have an 'href' attribute.
You can use the get_attribute property of an element:

button = driver.find_element_by_class_name('Next_button')
href_data = button.get_attribute('href')
if href_data is None:
  is_clickable = False

Gets the given attribute or property of the element.

This method will first try to return the value of a property with the given name. If a property with that name doesn’t exist, it returns the value of the attribute with the same name. If there’s no attribute with that name, None is returned.

Values which are considered truthy, that is equals “true” or “false”, are returned as booleans. All other non-None values are returned as strings. For attributes or properties which do not exist, None is returned.

More on Using get_attribute

You could also try is_displayed or is_enabled




ANSWER 2

Score 4


Use this to get classes element.get_attribute("class") and check if list of classes contains characteristic class (for example "disable") from your html framework which is used to describe unclickable buttons