Failed to set checkbox via Selenium in Python

Why can't I click the next checkbox on the page https://realty.yandex.ru/add via Selenium in Python?

enter image description here

import traceback

import selenium.webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import selenium.webdriver.support
import selenium.webdriver.support.ui


explicit_wait_timeout_secs = 10


def wait_for_element_presence(driver, find_type, web_element):
    return selenium.webdriver.support.ui.WebDriverWait(driver, explicit_wait_timeout_secs).until(EC.presence_of_element_located((find_type, web_element)))


def wait_for_element_clickable(driver, find_type, web_element):
    return selenium.webdriver.support.ui.WebDriverWait(driver, explicit_wait_timeout_secs).until(EC.element_to_be_clickable((find_type, web_element)))


try:
    driver = selenium.webdriver.Chrome()

    driver.get('https://realty.yandex.ru/add/')

    # element = wait_for_element_clickable(driver, By.NAME, 'lift')  # TimeoutException
    element = wait_for_element_presence(driver, By.NAME, 'lift')  # WebDriverException: Message: unknown error: Element is not clickable at point (203, 899). Other element would receive the click: <span class="checkbox__box">...</span>
    element.click()
except Exception:
    print('ERROR: \n' + traceback.format_exc())

try:
    driver.quit()
except Exception:
    pass

If I try to wait for the "clickability" of this element, it gives me an error TimeoutException. If I try to wait for the presence of this element, it gives me the error "the element is not clickable".

However, I can click this checkbox through Javascript:

driver.execute_script("document.getElementsByName('lift')[0].click();")

It also works in Firefox btw.

Why? What am I doing wrong? How can i fix this?

Thanks in advance.

+4
source share
1 answer

span, input name="lift":

element = driver.find_element_by_xpath('//span[span/input[@name="lift"]]')
element.click()

Chrome, Firefox:

enter image description here

, , :

def scroll_element_into_view(driver, element):
    """Scroll element into view"""
    y = element.location['y']
    driver.execute_script('window.scrollTo(0, {0})'.format(y))

element = driver.find_element_by_xpath('//span[span/input[@name="lift"]]')
scroll_element_into_view(driver, element)
element.click()
+5

Source: https://habr.com/ru/post/1569432/


All Articles