Estoy tratando de hacer clic en este elemento web particular de este sitio: https://www.milanofinanza.it/quotazioni/ricerca/listino-completo-2ae?refresh_cens
Lo he intentado de muchas maneras diferentes, pero sigo recibiendo el mismo error (elemento no interactuable).
Mi código se ve así:
wd.find_element(By.XPATH,"//*[@id='mainbox']/div[2]/div[2]/div[4]/div/div[1]/div/button[4]").click()En realidad, se detecta el elemento, pero por algún motivo no se puede hacer clic en él.
Se me ocurren dos posibles explicaciones:
.click() de Selenium. No estoy familiarizado con los atributos ng- , por lo que tal vez sea solo una cuestión de localización del idioma, pero sospecho que el selenio puede estar buscando un atributo onclick .Mis sugerencias:
//*button[text()=Successiva]getDataTableNextClick()wait=WebDriverWait(driver,20) try: wait.until(EC.element_to_be_clickable((By.XPATH,"//li[@class='page-item']/button[.='Successiva']"))).click() except: passPara simplemente hacer clic en ese elemento, simplemente busque el botón con ese texto.
Para recorrer 15 páginas podrías hacer
current=1 last=15 while True: try: if current == last: break current+=1 wait.until(EC.element_to_be_clickable((By.XPATH,"//li[@class='page-item']/button[.='Successiva']"))).click() except: breakAhora este sitio es un poco más complicado si quieres pasar las 15 páginas ya que la paginación no desactiva el botón.
current="1" old="2" while True: try: if current == old: break old=current wait.until(EC.element_to_be_clickable((By.XPATH,"//li[@class='page-item']/button[.='Successiva']"))).click() current=wait.until(EC.visibility_of_element_located((By.XPATH,"//*[contains(@class,'page-item ng-scope active')]"))).text except: breakImportar:
from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC