my function for finding the elements looks like this:
def find_element(val, elem=None, by=By.CLASS_NAME) -> WebElement:
if elem is None:
elem = driver
element = WebDriverWait(elem, 10).until(EC.element_to_be_clickable((by, val)))
return element
i am calling this function simply everytime i need to find the element.
weekday = find_element("weekday")
weekday.click()
there is one specific problematic button that is sometimes working and sometimes not. it gives me this error : selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element ... is not clickable at point (840, 12). Other element would receive the click:
issue is that sometimes it works (when i am using bigger monitor) sometimes it doesnt, also when i run the debugger, and wait couple of seconds 10/20 then it becomes clickable. I dont understand why its not clickable when the element_to_be_clickable says that it is.
ps driver.execute_script("arguments[0].click();", weekday) doesnt do anything at all, tried it as well.
CodePudding user response:
to solve
selenium.common.exceptions.ElementNotInteractableException: Message: element
You should debug your code like the below:
Make sure the browser is launched in full screen using
driver.maximize_window()
Use
ActionChains
:ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.visibility_of_element_located(By.CLASS_NAME, ".weekday"))).click().perform()
Imports:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
CodePudding user response:
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)