0

I couldn't find and click the element. HTML is as follows:

<button _ngcontent-c2=""> INICIAR SESIÓN </button>

I tried using the code:

login_element = driver.find_element_by_xpath('/html/body/app-root/div/div/app-login/form/div/div/button').click()

This is the error i got:

Traceback (most recent call last):
  File "/home/eitan/PycharmProjects/pysel/autopro.py", line 36, in <module>
    login_element = driver.find_element_by_xpath('/html/body/app-root/div/div/app-login/form/div/div/button').click()
  File "/home/eitan/PycharmProjects/pysel/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/home/eitan/PycharmProjects/pysel/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "/home/eitan/PycharmProjects/pysel/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/eitan/PycharmProjects/pysel/venv/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button _ngcontent-c2="">...</button> is not clickable at point (624, 648). Other element would receive the click: <img _ngcontent-c2="" src="assets/static/images/login.svg">
  (Session info: chrome=74.0.3729.131)
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 4.15.0-47-generic x86_64)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
ENcy
  • 324
  • 4
  • 7

2 Answers2

0

As the element is an Angular element, to click() on the element with text as INICIAR SESIÓN you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategy:

  • Using XPATH:

    driver.execute_script("arguments[0].click();",WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(., 'INICIAR SESIÓN')]"))))
    
  • 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
  • dosent work : selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (624, 648). Other element would receive the click: (Session info: chrome=74.0.3729.131) (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 4.15.0-47-generic x86_64) – ENcy May 14 '19 at 14:54
  • @ENcy Updated the answer, let me know the status. – undetected Selenium May 14 '19 at 14:59
0

Try the following xpath

login_element = driver.find_element_by_xpath("//button[contains(.,'INICIAR')]"
login_element.click()

EDITED

Seems like webdriver unable to click on the button element.inject java scripts executor to click on the button element or use action class to click.

login_element = driver.find_element_by_xpath("//button[contains(.,'INICIAR SESIÓN')]")
driver.execute_script("arguments[0].click();",login_element)

OR Action class.

login_element = driver.find_element_by_xpath("//button[contains(.,'INICIAR SESIÓN')]")
ActionChains(driver).move_to_element(login_element).click().perform()

Use the following imports for action class.

from selenium.webdriver.common.action_chains import ActionChains
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • That thhe one woh work for me: login_element = driver.find_element_by_xpath("//button[contains(.,'INICIAR SESIÓN')]") driver.execute_script("arguments[0].click();",login_element) – ENcy May 15 '19 at 08:53