driver.find_element(By.XPATH, "/html/body/div/div[2]/main/div[2]/div/section/div[2]/div/form/input")
gives the following message>
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div/div[2]/main/div[2]/div/section/div[2]/div/form/
The website (URL) is:
https://sede.administracionespublicas.gob.es/pagina/index/directorio/icpplus
CodePudding user response:
It seems that the element you wanted to click is not clickable you can use the same locator
with below code or use the code as is.
from selenium.webdriver.common.by
import By
from selenium.webdriver.support.ui
import WebDriverWait
from selenium.webdriver.support
import expected_conditions as EC
element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.ID, "submit"))) # if you want to click on the button Acceder al Procedimiento
element.click();
CodePudding user response:
Use WebDriverWait()
and wait for element to be clickable and following xpath to click on the element.
absolute xpath
is always fragile, you should use relative xpath
to identify the element.
You can learn form here Xpath cheatsheet
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH, "//input[@value='Acceder al Procedimiento']"))).click()
Import below libarries
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By