0

I use selenium to register something on a customer in my system. The response is what I want to make sure the test is ok.

The response is:

<div class="ui-messages-info ui-corner-all">
<span class="ui-messages-info-icon"></span>
<ul>
<li>
<span class="ui-messages-info-summary">Name Name was registered -   torsdag 02.03.2017 kl. 09.38.</span>
</li>
</ul>
</div>
</div>

I want to verify that the text "was registered" is present, and the test to fail if the text is not present.

How can I write a check for that in selenium?

I was thinking something like this:

WebElement verify = driver.findElement(By.something("was registered"));
Chanda Korat
  • 2,453
  • 2
  • 19
  • 23
Magnus Jensen
  • 905
  • 6
  • 36
  • 73
  • refer this question and answer. http://stackoverflow.com/questions/41974209/what-is-the-actual-difference-between-assertequals-vs-asserttrue-in-testng – Jainish Kapadia Mar 02 '17 at 09:33

2 Answers2

0
String el_text = driver.findElement(By.class("ui-messages-info-summary")).getText();

and then check if its inside

if "was registered" is in el_text:
CrazyCrow
  • 4,125
  • 1
  • 28
  • 39
whoopdedoo
  • 2,815
  • 23
  • 46
0

Try this,

driver.find_elements_by_xpath("//*[contains(text(), 'was registered')]")

If this element is present that means it has text "Was registered".

Chanda Korat
  • 2,453
  • 2
  • 19
  • 23