mardi 30 novembre 2021

Clicking on a check box using selenium - Python

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> 



Aucun commentaire:

Enregistrer un commentaire