-2

I am composing an email and sending it to myself. I want to verify the title and the body has the same text I gave (note: the body might contain extra text like the signature added to it) What is the best way in selenium to verify if the body contains the text I have sent? For eg:- I have sent text "hello" into my body, but after sending it now has "hello sent fromxxx" Using Java. Looking for selenese commands that can verify this.e

Can someone please suggest

I am using something like this

 String bodyText = driver.findElement(By.tagName("body")).getText();
 Assert.assertTrue("Text not found!", bodyText.contains(text));
Andersson
  • 51,635
  • 17
  • 77
  • 129
Ashvitha
  • 5,836
  • 6
  • 18
  • 18
  • If you use web-browser (e.g. `Firefox`, `Chrome`...) to check your mail, you should define `HTML` of target element that you need to verify, if you use email client (like `MS Outlook`) you cannot use `selenium` for this purpose – Andersson Nov 07 '16 at 19:58
  • I am using a web browser. Can you provide the syntax if possible – Ashvitha Nov 07 '16 at 20:07
  • `selenium` works with programming language. Have you tried it? Which language you use? To handle elements you should get `HTML` source. You can get it with `F12` or by clicking mouse right-button on element and choosing something like `Explore element` or `Get element source`... – Andersson Nov 07 '16 at 20:22
  • Please read [ask]. Please provide the code you have tried and the execution result including any error messages, etc. Also provide a link to the page and/or the relevant HTML. – JeffC Nov 07 '16 at 21:05
  • Using JAVA. I am looking for selenium code that validates using contains or anything similar to that. – Ashvitha Nov 07 '16 at 21:09

1 Answers1

1

Your Code

bodyText.contains(text);

will by itself return a boolean value that is True or False and the AssertTrue's output will be displayed in your console if the boolean value is false.

GraveyardQueen
  • 771
  • 1
  • 7
  • 17