Selenium using Python

Asked

Viewed 68 times

-1

I’m making a bot that goes through a page until it reaches where you download a file, but I can’t access a link using the driver.find_element_by_xpath, because the page link is as href and does not have a class for which I identify. Below is my code:

<a href="https://www.excelcontabilidade.com.br/tabela-de-correcao-monetaria/indicadores"><a/>

My code in Python:

WebDriverWait(driver,5).until(EC.visibility_of_element_located((By.XPATH,"""//*[@]]""")))
driver.find_element_by_xpath("""//[*href="https://www.excelcontabilidade.com.br/tabela-de-correcao-monetaria/indicadores""]""").click()

Can anyone tell me how to access the hyper-link without a class, id or name defined?

  • This XPATH seems to be wrong. To get the right XPATH, open the page, right click and click on "inspect element" or something like that. Inside the 'inspect element', select this part of the code where you have the element that you want to pick up, right-click and select "Copy -> xpath"

2 answers

0

No classes and no identification, just putting the content (the link) inside href, same in this code (which, if the site changes the link, may end up causing errors in your code):

variavel = driver.find_element_by_xpath('//a[@href="https://www.excelcontabilidade.com.br/tabela-de-correcao-monetaria/indicadores"]')
variavel.click()

Or simply driver.find_element_by_xpath('//a[@href="https://www.excelcontabilidade.com.br/tabela-de-correcao-monetaria/indicadores"]').click()

Always check the errors generated in the console when running Selenium to identify errors, test the code I gave you and if any errors occur let me know!

-3

All tags use the title, you can do so:

find_element_by_xpath("//a[@title='https://www.excelcontabilidade.com.br/indicador/TJ-Maranhão']")

Then tell me if it worked

Browser other questions tagged

You are not signed in. Login or sign up in order to post.