Home > front end >  Selenium get URL of "a" Tag without href attribute
Selenium get URL of "a" Tag without href attribute

Time:11-12

I'm facing an element like:

<li _ngcontent-bcp-c271="">
   <a _ngcontent-bcp-c271="">2018</a>
   <!---->
   <!---->
</li>

This element is clickable but since it does not have a href attribute, and I think it should use some script for the click event, I don't have a solution to get the URL from this element.

The code that I use most of the time is as follows:

driver.find_element(By.TAG_NAME, 'li').find_element(By.TAG_NAME, 'a').get_attribute('href')

Update:
I need to know the URL before I click on the bottom.

CodePudding user response:

The easiest way to know its URL is to click it and then get page's url with:

driver.current_url

Another way is to get the javascript of this page and find in it the code that is responsible for clicking on this link and get the url from it if it is written explicitly there.

CodePudding user response:

The answer is: NO, you can not do that.
You can not get the URL before clicking such elements since URL is dynamically created by script etc, it is not statically kept on the page.

  • Related