1

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?

3
  • Please show us the whole code and Exception. Commented Jan 19, 2012 at 6:32
  • It looks like the error is a syntax error because you're missing a closing ). Try it with the closing ). Commented Jan 19, 2012 at 17:58
  • @Chris I have tried elem = self.browser.find_element_by_xpath("//div[@id='s-resultlist-header']//div[@class='s-resultlist-hits']//span") But i get error u'Unable to locate element:{"method":"xpath","selector":" Commented Jan 23, 2012 at 6:53

1 Answer 1

1
elem = self.browser.find_element_by_xpath("//div[@id='s-resultlist-header']/div[@class='s-resultlist-hits']/span");
Sign up to request clarification or add additional context in comments.

3 Comments

@Fabio There is no exception,but I just want to retrieve text instead of page try: self.assertTrue(self.verifytext("Total hits: 203")) text = self.browser.page_source print text elem = self.browser.find_element_by_xpath("//div[@id='s-resultlist-header']/div[@class='s-resultlist-hits']/span") print elem "stop" except AssertionError as e:self.fail(self,msg=None) def verifytext(self,string): if str(string) in self.browser.page_source:return True else:return False
Thanks for reply. I tried the above solution suggested by you ,but I get a error u'Unable to locate element: {"method":"xpath","selector": ; Stacktrace: Method newInstance0 threw an error in None
Please bare with the syntax of text , as Ima still new to this forum , and might have missed rules for replying comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.