2

Goal is to click on a checkbox on login page. I find the element by XPATH, but can't click on it.

>>> elem = driver.find_element_by_xpath("//input[@type='checkbox'][@name='conditions']")
>>> elem.is_displayed()
False
>>> elem.is_enabled()
True
>>> elem.get_attribute('outerHTML')
u'<input type="checkbox" class="custom-control-input" name="conditions">'

When I try elem.click(), exception occurs: selenium.common.exceptions.ElementNotVisibleException: Message: element not visible but element is clearly visible, since the page is loaded and I work from terminal.

Other error when I use different selector is: driver.find_element_by_xpath('/html/body/div[2]/main/section/div/div[3]/div/div[1]/form/p[1]/label/input').click()

selenium.common.exceptions.WebDriverException: Message: unknown error: Element <input type="checkbox" class="custom-control-input" name="conditions"> is not clickable at point (51, 549). Other element would receive the click: <span class="custom-control-description font-weight-regular">...</span>

I tried with injecting JavaScript but didn't work. driver.execute_script("arguments[0].style.visibility = 'visible';",elem)

Any ideas how to work around this?

1
  • try to explicit wait for the visibility of element then click on it. Commented Apr 12, 2018 at 12:35

2 Answers 2

2

As per your code trials when you try :

elem.click()

You are seeing :

selenium.common.exceptions.ElementNotVisibleException: Message: element not visible

Which means the desired element is still not visible in the HTML DOM

Even before trying to click when you are try :

elem.is_displayed()

You are seeing :

False

But when you try :

elem.is_enabled()

You are seeing :

True

So combining all these observations it can be either of the situations :

  • Element is present in the DOM but still not visible/interactable. In this case you need to induce WebDriverWait and then invoke click() as follows :

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@type='checkbox' and @name='conditions']"))).click()
    
  • Element is present in the DOM but not within the Viewport. In this case you need to invoke execute_script() to bring the element within the Viewport and then invoke click() as follows :

    elem = driver.find_element_by_xpath("//input[@type='checkbox' and @name='conditions']")
    driver.execute_script("arguments[0].scrollIntoView(true);", elem)
    elem.click()
    
  • There is a possibility that the Locator Strategy you have adapted is not unique and identifies multiple WebElements and the first element to be identified may be hidden. In this case is_displayed() will always return False and you have to construct a unique Locator Strategy which identifies the intended element uniquely.
  • There is a possibility that the style attribute of the element is set to display: none; and in that case you have to use execute_script() method as follows :

    elem = driver.find_element_by_xpath("//input[@type='checkbox' and @name='conditions']")
    driver.execute_script("arguments[0].removeAttribute('style')", elem)
    elem.click()
    
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @DebanjanB great answer, I tried and double checked all of it, but always get the error: Element ... is not clickable at point ... selenium.common.exceptions.WebDriverException: Message: unknown error: Element <input type="checkbox" class="custom-control-input" name="conditions"> is not clickable at point (51, 286). Other element would receive the click: <span class="custom-control-description font-weight-regular">...</span>
0

You can use this XPATH :- //input[@type='checkbox'and @name='conditions']

For below error:- Use wait before click event

selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point (51, 549). Other element would receive the click: ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.