Recover link when using click() from Python

Asked

Viewed 301 times

0

I need to recover the url address when clicking on the link, I am using Selenium with chrome_options.add_argument("--headless")

My current code:

links = driver.find_elements_by_partial_link_text('Excel')
for link in links:
    link.click()

tried to use the driver.current_url but as a click if I use browser rendering it opens a new tab and then closes.

The idea is to download several files but as I am using the headless so I searched the best option would be to use a driver.get directly in the URL when clicking on the link.

1 answer

0


You can take the attribute of the tag that contains the link, as in the example:

links = driver.find_elements_by_partial_link_text('Excel')
for link in links:
    print(link.get_attribute('href'))
  • Wonder worked, and I cracked my head.

Browser other questions tagged

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