I am trying to click on this particular web element from this site: https://www.milanofinanza.it/quotazioni/ricerca/listino-completo-2ae?refresh_cens
I have tried in many different ways but i still get the same error (element not interactable).
My code looks like this:
wd.find_element(By.XPATH,"//*[@id='mainbox']/div[2]/div[2]/div[4]/div/div[1]/div/button[4]").click()
The element is actually detected but for some reason it isn't clickable.
I can think of two possible explanations:
.click() expects. I am not familiar with ng- attributes, so maybe it's just a language localization thing, but I suspect that selenium may be looking for an onclick attribute.My suggestions:
//*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:
pass
To simply click on that element just look for the button with that text.
To go through 15 pages you could do
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:
break
Now this site is a little trickier if you want to go pass the 15 pages since the pagination doesn't disable the button.
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:
break
Import:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC