5

Why am I unable to click the following 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'm trying to wait for the "clickability" of this element, it gives me TimeoutException error. If I'm trying to wait for the presence of the element, it gives me "element is not clickable" error.

However, I can click this checkbox via Javascript:

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

Also it works in Firefox btw.

Why? What am I doing wrong? How can I fix it?

Thanks in advance.

15
  • 1
    have you tried using Firefox driver? it works on mine
    – Anzel
    CommentedDec 30, 2014 at 14:19
  • @Anzel Yep, just tried it and it worksCommentedDec 30, 2014 at 14:19
  • so it's not working on Chrome driver?
    – Anzel
    CommentedDec 30, 2014 at 14:21
  • @Anzel Yep, you're rightCommentedDec 30, 2014 at 14:21
  • 1
    There are multiple elements with the same name so that might be the reason what i believe, Instead of My name locator try using xpath locator with below value and see what happens. //label[contains(text(),'Лифт')]CommentedDec 30, 2014 at 14:27

2 Answers 2

9

You need to click on the span tag that is a parent of a parent of the input tag with name="lift":

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

Works for me in both Chrome and Firefox:

enter image description here

To be safe, you can also scroll to an element before clicking:

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() 
2
  • Do you know why? Shouldn't it work to click on the checkbox itself?
    – rifaco
    CommentedJan 27, 2015 at 17:42
  • 1
    @rifaco well, this is a wonderful and mysterious world of browser automation and web-scraping - it really depends on how this particular web-page is implemented, cause there can be all sorts of techniques involved. Just trying to say that "shouldn't it work" is not a valid question - the only answer could be "it depends" :) Thanks.
    – alecxe
    CommentedJan 27, 2015 at 17:49
1

we can use this to click on an element using Javascript

element=driver.find_element(By.ID,"sdd") driver.execute_script("arguments[0].click();", element) 

or

driver.execute_script("arguments[0].click();", driver.find_element(By.ID,"sdd")) 

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.