Tuesday 18 March 2014

How to click on the links in selenium webdriver in python?

We have 2 methods that can be used to identify the links in  selenium.

  1. find_element_by_link_text  (complete link)
  2. find_element_by_partial_link_text  (part of link)

These methods can be used to identify only links in the web page.
Example – Suppose you want to click on the link “Home”. You can use below syntax to click on the link.


from selenium import webdriver

#driver = webdriver.Chrome("F:\\selenium\\Csharp\\iedriverserver.exe")

#driver = webdriver.Chrome("F:\\selenium\\Csharp\\chromedriver.exe")

driver = webdriver.Firefox()

driver.get("http://register.rediff.com/register/register.php")

try:

 link = driver.find_element_by_link_text("Home")

 link.click()

 driver.close()

except Exception as e:

    print ("Exception occured", format(e));

finally:

    driver.quit()

    print ("finally")


What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com

No comments:

Post a Comment

Buy Best Selenium Books

Contributors