user1117498
user1117498

Reputation: 29

retrieve text from the HTML source page using selenium with python

My HTML page looks like this :

<div id="s-resultlist-header" class="s-resultlist-header" style="width: 607px;">
  <div class="s-resultlist-hits">
    <span>Total hits: 203</span>
  </div>
</div>

I want to retrieve a value "Total hits: 203" within the span into a variable. I need to validate if total results is equal to 203. Language used: Python.

I have tried:

elem = self.browser.find_element_by_xpath(//div[@class='s-resultlist-hits']span

but gives a error: Expected ). Can anyone correct the syntax?

I have also tried:

print browser.pagesource

But it prints the entire page source. Can anyone guide?

Upvotes: 1

Views: 2070

Answers (1)

faramka
faramka

Reputation: 2234

elem = self.browser.find_element_by_xpath("//div[@id='s-resultlist-header']/div[@class='s-resultlist-hits']/span");

Upvotes: 1

Related Questions