9

How can I view the source of a page between the "title" and "meta" tags using Selenium WebDriver with Java?

2 Answers 2

15

You can try driver.getPageSource() after you have loaded the page.

link to java doc

Sign up to request clarification or add additional context in comments.

1 Comment

The javadoc link is broken.
7

You can compare the Title of a page as below code:

String actualTitle = driver.getTitle();
String expectedTitle = "My Title";
assertEquals(actualTitle, expectedTitle);

If you want to get page source you can get by using the following java code:

String pageSource = driver.getPageSource();

If you want to verify a particular text is present or not on the page, do as below:

boolean isTheTextPresent = driver.getPageSource().contains("your text");
assertTrue(isTheTextPresent);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.