Clicking on a link via selenium

canbaran picture canbaran · Sep 3, 2013 · Viewed 69.6k times · Source

I am trying to do some webscraping via Selenium. My question is very simple: How do you find a link and then how do you click on it? For instance: The following is the HTML that I am trying to web-scrape:

<td bgcolor="#E7EFF9">
  <a href="javascript:selectDodasaDetdasdasy(220011643,'Kdasdası');" target="_self">
   Details
  </a>
</td>

So, as you can see the word "Details" is a link.

How can I find that link using Selenium and click on it?

Answer

falsetru picture falsetru · Sep 3, 2013

You can use find_element_by_link_text:

For example:

link = driver.find_element_by_link_text('Details')

To Click on it, just call click method:

link.click()