How can I view the source of a page between the "title" and "meta" tags using Selenium WebDriver with Java?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can try driver.getPageSource()
after you have loaded the page.
link to java doc
回答2:
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);