Web scraping with Python – how to click on date of same value
Question:
I’m trying to click on the button that contains the text "30 de novembro" but when I use my code it clicks on the "30 de outubro" button
How to fix?
Here’s the code I’m using
selecdia = navegador.find_element(by=By.LINK_TEXT, value='30')
selecdia.click()
sleep(1)
Answers:
Looks like the title attribute is the only way to uniquely identify the link you wish to click, therefore in Selenium 4 syntax:
selecdia = navegador.find_element(By.CSS_SELECTOR, "a[title='30 de novembro']")
or:
selecdia = navegador.find_element(By.XPATH, "//a[@title='30 de novembro']")
I’m trying to click on the button that contains the text "30 de novembro" but when I use my code it clicks on the "30 de outubro" button
How to fix?
Here’s the code I’m using
selecdia = navegador.find_element(by=By.LINK_TEXT, value='30')
selecdia.click()
sleep(1)
Looks like the title attribute is the only way to uniquely identify the link you wish to click, therefore in Selenium 4 syntax:
selecdia = navegador.find_element(By.CSS_SELECTOR, "a[title='30 de novembro']")
or:
selecdia = navegador.find_element(By.XPATH, "//a[@title='30 de novembro']")