0

I'm using web driver to automate a test case. I'm trying to verify the text present in the page or not. I'm doing the following, but I don't know how to verify the textPresent is what I'm actually looking for.

textPresent = driver.find_element_by_xpath ("//span/p") 

then when I did textPresent.text it's giving the text "An error occured processing Order" where I'm actually looking for "Successfuly added to processing" in the same xpath location. So in this situation, I want to fail the test case. How do i do that?

4
  • The straightforward solution is to add id attribute to the paragraph tag, so that you could easily access the element. After that you can access the text attribute of the returned object and compare. //span/p is a too broad selector and does not guarantee that the returned element is the one you are looking for. Commented May 12, 2014 at 19:08
  • There is only one particular text in the entire page. And there is no id associated with this text. :( Commented May 12, 2014 at 19:35
  • is there only one span on the page though? Include a snippet of your HTML and I'm sure somebody will be able to point out a better selector Commented May 12, 2014 at 22:39
  • assert(textPresent == 'Successfully added to processing') Commented May 13, 2014 at 5:51

1 Answer 1

1

We should include a check point to verify the equality of actual text with expected :

expectedText = "Successfuly added to processing"; textPresent = driver.find_element_by_xpath ("//span/p"); if textPresent != expectedText <Write fail condition here e.g. return "Fail" or raise Exception("Fail")> 
Sign up to request clarification or add additional context in comments.

2 Comments

above is working fine, but i'm hitting a problem in another similar area. I just want to verify the first line exists and then use assert don't want to verify the content after <br>. How do i do that?
<div> <div class="alertbox alert ng-scope alert-success" ng-class="type && "alert-" + type" close="closeAlert($index)" type="alert.type" ng-repeat="alert in alerts"> <button class="close" ng-click="close()" type="button" ng-show="closeable">×</button> <div ng-transclude=""> <span class="ng-scope ng-binding" ng-bind-html-unsafe="alert.msg"> <p> Successfuly added to execution processing! <br> <br> {"Date":"5/13/2014","$$hashKey":"00F","memberId":"TOP","instrumentType":"MEE","Symbol":"IPL","quantity":"400","price":113.99} </p> </span> </div> </div> </div>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.