How to assert text of webpage using selenium 2.0?



How to assert text of webpage using selenium 2.0?..

Answer / Raj Bhushan Dube

To assert text on a webpage using Selenium 2.0 (WebDriver), you can use the `getText()` method followed by `assertEquals()` for verification:
1. Get the text from the desired element: `String expectedText = driver.findElement(By.xpath("//your xpath")).getText();`
2. Verify the actual text with the expected text using `assertEquals()`: `assertEquals(expectedText, "Expected Text");`

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Selenium Interview Questions

How do you read data from excel?

1 Answers  


What the webdriver supported mobile testing drivers do you know?

1 Answers  


How do you add check points or verification points in selenium?

1 Answers  


How to perform right click action (context click) in selenium webdriver?

1 Answers  


Which of the selector ID, name, XPath or CSS should I use?

1 Answers  


What are startpoints and breakpoints in selenium?

1 Answers  


Differentiate between ‘/’ and ‘//’.

1 Answers  


How would you test your element locator?

1 Answers  


What is the object repository?

1 Answers  


What is the alternative to driver.get() method to open an url using selenium webdriver?

1 Answers  


What are the annotations available in testng?

1 Answers  


How to find more than one web element in the list?

1 Answers  


Categories