krisk
krisk

Reputation: 237

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?

Upvotes: 10

Views: 24651

Answers (1)

Amey
Amey

Reputation: 8548

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

Upvotes: 11

Related Questions