0

I am trying to click on a check box. Below is the HTML Code

<div class="mb-1 p-3 termsCheck">
            <input class="form-check-input float-end" type="checkbox" value="" id="flexCheckDefault" required=""> <label class="form-check-label float-end" for="flexCheckDefault"><span>
                    Agree to Terms &amp; Conditions </span> / <span> أوافق على الشروط والأحكام
            </span> </label>
        </div>

I am using the below code to click on it.

check = driver.find_element(By.CSS_SELECTOR, '#flexCheckDefault')
check.click()

I am getting this error

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (477, 1222)

full error:

     driver.find_element(By.XPATH, "//label[@for='flexCheckDefault']").click()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 81, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 710, in _execute
    return self._parent.execute(command, params)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (292, 1317)
  (Session info: chrome=91.0.4472.101)
Stacktrace:
#0 0x556910005919 <unknown

Can some please help me with this.

when I am using the below code I am getting this error::

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for='flexCheckDefault']"))).click()

Error

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for='flexCheckDefault']"))).click()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 81, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 710, in _execute
    return self._parent.execute(command, params)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (292, 467)
  (Session info: chrome=91.0.4472.101)
Stacktrace:
#0 0x563f45805919 <unknown> 
raptorzee
  • 151
  • 1
  • 11

2 Answers2

0

To click() on the checkbox beside the label Agree to Terms & Conditions you can use either of the following Locator Strategies:

  • Using css-selector:

    driver.find_element(By.CSS_SELECTOR, "label[for='flexCheckDefault']").click()
    
  • Using xpath:

    driver.find_element(By.XPATH, "//label[@for='flexCheckDefault']").click()
    

Ideally, to click on a clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS-SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for='flexCheckDefault']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for='flexCheckDefault']"))).click()
    
  • 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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I tried and I am getting this error: aise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (292, 1317) – raptorzee Nov 30 '21 at 11:53
  • Checkout the updated answer and let me know the status. If you still see the error, update the question with the complete error stacktrace even beyond `Element is not clickable at point (477, 1222)` – undetected Selenium Nov 30 '21 at 11:54
  • I updated the question. when i an using what youve suggested, i am getting a similar error – raptorzee Nov 30 '21 at 12:01
  • More of the stacktrace i.e. `#0 0x563f45805919` lines would have been helpful. You seem to be using _chrome=91.0.4472.101_, can you upgrade to `chrome=96.0` and `chromedriver=96.0` and get me the status please? – undetected Selenium Nov 30 '21 at 12:06
  • @raptorzee Can you replace your line where you are clicking with this: driver.execute_script("arguments[0].click();", check)") – QualityMatters Nov 30 '21 at 12:14
  • 1
    this is how it works. thank a lot element = driver.find_element_by_xpath('/html/body/div[1]/form/div[6]/input') driver.execute_script("arguments[0].click();", element) @QualityMatters can you please post it as an answer so i can make it the answer – raptorzee Nov 30 '21 at 12:23
  • @raptorzee done. If you will run it with jenkin (windows slave) which opens with a different screen resolution or in any machine having different resolution, then also this solution will work. – QualityMatters Nov 30 '21 at 12:31
0

ElementClickInterceptedException is usually comes when the element is not in viewport. In such cases, JavaScript executor works perfectly in selenium scripts. Below code should work:

driver.execute_script("arguments[0].click();", element)
QualityMatters
  • 895
  • 11
  • 31