How to judge that the element is clickable or not? – Selenium

enter image description here

For the URL I’m trying to induce clicks on next page button. To make sure that the button is clickable or not I try the following :

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.fa.fa-angle-right')))

But this gives true for even the last page. Where am I going wrong in my understanding? How can I judge that a button is clickable or not anymore? On the last page, the next page button is grayed out.


If you pay attention, when the button is getting grayed out, it has a class attribute whose attribute value is getting changed to disabled.

You can probably make a function and put the below code inside that, can call that as per your requirement.

Sample code :

wait = WebDriverWait(driver, 20)
next_button = wait.until(EC.element_to_be_clickable((By.XPATH, "//a[@aria-label='next page']")))
    if next_button.get_attribute('class') == "disabled":
        print('Next button is not clickable anymore')
        print('Next button is available')
    print('Something went wrong')

Imports :

from import WebDriverWait
from import By
from import expected_conditions as EC