I know there’s someone else having the same problem as me, but it turns out he’s using a different code as me. (I’m NOT having the same problem with this : Selenium identifies the button as clickable when it wasn’t) So, apparently I’ve tried to make the page refreshes everytime the button is unclickable or disabled using the WebDriverException error.
So, everytime the Selenium drops an error of WebDriverException which an error that occurs if you attempt to click a disabled object (If I’m not wrong), it’ll refresh the page until it’s enabled. It has worked for a few days back, but for some reason I don’t know what I’ve done, It suddenly starts malfunctioning?.
It acts like nothing happened, and drops no error even though the element is clearly disabled. I tried printing the variable just to check if the element actually stored in the variable. But, it did. So I don’t know what could be causing the problem. I’ve put the code below, every helpful answer I appreciate them!. Thank you!.
purchasenow = browser.find_element_by_xpath("/html/body/div/div/div/div/div/div/div/div/div/div/div/button") purchasenow.click() print(purchasenow) while True: try: purchasenow.click() newtime() print("[INFO :] ORDER BUTTON ENABLED!, ATTEMPTING TO PUT ITEM IN CART...") webhook = DiscordWebhook(url=logs, content='[INFO :] ORDER BUTTON ENABLED!, ATTEMPTING TO PUT ITEM IN CART...') if withlogging == "y": response = webhook.execute() break except WebDriverException: newtime() print("[INFO :] ORDER BUTTON DISABLED!, REFRESHING THE PAGE...") webhook = DiscordWebhook(url=logs, content='[INFO :] ORDER BUTTON DISABLED!, REFRESHING THE PAGE...') if withlogging == "y": response = webhook.execute() browser.refresh() continue
EDIT [12/10/2020] : Tried making it sure with the is_enabled(), somehow it was detected as True or clickable. Still looking for possible solutions, please let me know in the Answers!.
click() on a WebElement there is a necessity to wait for the element and its children to completely render and become interactable.
def element_to_be_clickable(locator): """ An Expectation for checking an element is visible and enabled such that you can click it.""" def _predicate(driver): element = visibility_of_element_located(locator)(driver) if element and element.is_enabled(): return element else: return False return _predicate
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/div/div/div/div/div/div/div/div/div/button"))).click()
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
You can find a couple of relevant detailed discussions in: