How to validate a text (Assert) in a given field in Selenium Webdriver?

Asked

Viewed 4,841 times

-1

How do I validate a text in a given field?

The location is xpath:

html/body/div[1]/div/div[4]/article/div[1]/div/header/div[1]/h1

The text is "Congratulations! Successfully inserted".

How should I validate with assert? Java Language.

Thanks in advance!

  • Could someone help?

1 answer

0


Oops! Follow the code that can help you:

String textoElement = driver.findElement(By.xpath("html/body/div[1]/div/div[4]/article/div[1]/div/header/div[1]/h1\n")).getText();
        assertEquals("texto-esperado", textoElement);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.