Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get text from link - selenium python

I'm trying to get "Home" text from

<li class="active"><a href="#">Home</a></li>

I tried

element = self.browser.find_element_by_class_name('active')
print element.find_element_by_tag_name('a').text

but it returns empty string. What am I missing here?

like image 432
krisk Avatar asked Jun 22 '13 14:06

krisk


1 Answers

Do it using CSS - .find_element_by_css_selector("li.active a"), or using xpath .find_element_by_xpath("//li[@class='active']/a")

So this is how it would like finally

element = self.browser.find_element_by_css_selector("li.active a")
print element.text
like image 160
Amey Avatar answered Sep 19 '22 18:09

Amey