'Click button with Selenium webdriver for Python does not work in function

I'm trying to do some web scraping for products. In this particular page, there is a "More Products" button, which I built a function to click as many times as needed to load all the products for my respective filter.

When I simply use like this, it works perfectly:

driver.find_element_by_class_name('cf-load-more').click()

But if I try to use it inside a function:

def pushButton(qty):
    pushes = math.ceil(qty/20) #20 products are displayed each time
    for p in range(pushes+1):
        driver.find_element_by_class_name('cf-load-more').click()
        time.sleep(5)

it results in this error, saying that the button is not clickable:

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source