Selenium – 'site' object has no attribute 'find_element_by_link_text'

Issue

I’m trying to write a python script that clicks a certain link in a table on a webpage. The only option I have to select this particular link is it’s link text, but selenium keeps telling me that the command “find_element_by_link_text” doesn’t exist even though it’s found on not only the official selenium docs but also multiple online selenium examples. Here’s the code snippet:

hac.find_element_by_link_text("View this year's Report Cards").click()

I cross-checked my selenium installation with one from the website and they seem to be the same. Was this feature deprecated or am I just missing something? I’m using selenium v.2.45.0 and python v.2.7.

Solution

You need to call the find_element_by_link_text() method using driver.

Here is a sample script that opens the Python home page, locates the link to the About page using its link text, and then clicks that link:

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("http://www.python.org")
driver.implicitly_wait(10)
elem = driver.find_element_by_link_text("About")
driver.implicitly_wait(10)
elem.click()

This page of the Selenium docs gives an overview of all of the find_element methods available, and shows how to call those methods.

Answered By – duhaime

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published