Python Selenium: Wait Until Element Is Clickable - Not Working

Python Selenium: Wait until element is clickable - Element is found using find_elements

You need to take care of a couple of things here as follows:

  • As the searchBar element is a clickable element ideally you need you need to induce WebDriverWait for the element_to_be_clickable() as follows:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "react-select-3-input"))).send_keys(address)
  • Again as the searchButton element is a clickable element you need you need to induce WebDriverWait for the element_to_be_clickable() as follows (in the worst case scenario assuming the searchButton gets enabled when search text is populated):

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, "sc-1mx0n6y-0"))).click()
  • Ideal dropdowns are html-select tags and ideally you should be using the Select class inducing WebDriverWait as follows:

    Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "cssSelector_select_element")))).select_by_visible_text("visible_text")
  • Finally, the ID and CLASS_NAME values which you have used e.g. react-select-3-input, sc-1mx0n6y-0, css-19bqh2r, etc looks dynamic and may change when you would access the application afresh or in short intervals. So you may opt to lookout for some other static attributes.

  • 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

python selenium element is not clickable at point even while using wait until element to be clickable

solved it by scrolling the element into middle of the page.

desired_y = (weekday.size['height'] / 2) + weekday.location['y']
current_y = (driver.execute_script('return window.innerHeight') / 2) + driver.execute_script(
'return window.pageYOffset')
scroll_y_by = desired_y - current_y
driver.execute_script("window.scrollBy(0, arguments[0]);", scroll_y_by)

Selenium wait until element is clickable, using relative element in python

You can use WebDriverWait and lambda to wait for the simple custom conditions:

wait = WebDriverWait(driver, 5)

parent = driver.find_element_by_css_selector("some element")

wait.until(lambda ignore:
parent.find_element_by_css_selector("child element").is_displayed()
and parent.find_element_by_css_selector("child element").is_enabled()
, "Element is clickable")

Use your own class:

class element_to_be_clickable(object):
def __init__(self, element):
self.element = element

def __call__(self, ignored):
if self.element.is_displayed() and self.element.is_enabled():
return self.element
else:
return False

wait = WebDriverWait(driver, 5)

parent = driver.find_element_by_css_selector("some element")
wait.until(element_to_be_clickable(parent.find_element_by_css_selector("input")), "Element is clickable")

How to loop until element clickable

I am not sure if your use of uppercase button is correct. Use the same syntax as in html.

One more thing: check your xpath with text():
It should be: //button[@type='submit' and text()='Zum Warenkorb hinzufügen']

Also, the general case for such loop in the case of one element is:

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException

wait = WebDriverWait(driver, 15)
while True:
try:
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@type='submit' and text()='Zum Warenkorb hinzufügen']")))
print("clickable")
element.click()
except TimeoutException:
break

selenium: wait for element to be clickable not working

The problem is stated in the error message.

Element ... is not clickable at point (621, 337). Other element would receive the click: ...

The problem is that some element, the details of which you removed from the error message, is in the way... on top of the element you are trying to click. In many cases, this is some dialog or some other UI element that is in the way. How to deal with this depends on the situation. If it's a dialog that is open, close it. If it's a dialog that you closed but the code is running fast, wait for some UI element of the dialog to be invisible (dialog is closed and no longer visible) then attempt the click. Generally it's just about reading the HTML of the element that is blocking, find it in the DOM, and figure out how to wait for it to disappear, etc.



Related Topics



Leave a reply



Submit