0

I am trying to get href link from "a" element on website, the problem is that it does not have "href" in it, so selenium gives me "element is not clickable".

The HTML code looks like this

<a class="download-file__link"
download="" 
data-masked="2532466d65646961253246636174616c6f67253246646f776e6c6f616473253246646174656e626c6174745f65787465726e253246322532463425324663253246612532463234636161633261393736372e706466" 
rel="nofollow">

When I click it inside my browser it shows the href.

<a class="download-file__link" 
download="" 
data-masked="2532466d65646961253246636174616c6f67253246646f776e6c6f616473253246646174656e626c6174745f65787465726e253246322532463425324663253246612532463234636161633261393736372e706466" 
rel="nofollow"
href="/media/catalog/downloads/datenblatt_extern/2/4/c/a/24caac2a9767.pdf">

How can I do it with Selenium so it will show the href afterwards?

I spent like 5 hours finding the solution but didnt find any.

Can you please help me?

Thank you

Jaxsss
  • 41
  • 3
  • _When I click it inside my browser it shows the href_: Why can't you do the same with [Selenium](https://stackoverflow.com/questions/54459701/what-is-selenium-and-what-is-webdriver/54482491#54482491)? – undetected Selenium Nov 28 '21 at 21:27
  • @DebanjanB it sounds like Selenium has decided the element isn't clickable, which is a thing it does sometimes. – Dylan Lacey Nov 29 '21 at 05:42
  • _element isn't clickable_ isn't the issue it seems, getting the `href` is what OP looking for. Let's discuss the issue in [Selenium](https://chat.stackoverflow.com/rooms/223360/selenium) room. – undetected Selenium Nov 29 '21 at 05:58

1 Answers1

0

There are two approaches you could try here.

Approach 1: ActionChains

Use ActionChains to either click on the element with an offset of 0,0 or get the location of the element, then click on those coordinates. Then check for the href.

Approach 2: Javascript

Write some Javascript code to find the element and click on it; It should ignore whether it thinks the element can be clicked or not and try to click on it.

You'll need to look up the docs for your Selenium bindings to find the executeScript method, then pass it some Javascript like this:

"$('#download-file__link').click()"
Dylan Lacey
  • 1,839
  • 12
  • 23