I am doing a test development tutorial for Django. http://www.tdd-django-tutorial.com/tutorial/1/
When I run a test, I get a problem with find_element_by_link_text. The error shows:
find_element_by_link_text - TypeError: Object of type 'WebElement' has no len()
The part of the test that is failing is this one:
polls_links = self.browser.find_element_by_link_text('Polls')
self.assertEquals(len(polls_links), 2)
If I remove those lines the tests work properly, the Polls model is added on the admin. In the admin site, during Selenium test, there are 2 links with the text ‘Polls’.
The problem does not seem to be that it is not recognizing them, the problem seems to be what find_element_by_link_text returns…I don’t know
Can anyone point me in the right direction? I did some research and apparently it has to do with Selenium driver for Firefox, but I have not been able to clear it up.
This line is your problem.
You need to add the
.textmethod to return the text of the element and not the element itself.