getPageSource() in Selenium WebDriver(a.k.a Selenium2) using Java

坚强是说给别人听的谎言 提交于 2019-11-28 03:29:56

问题


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);


来源:https://stackoverflow.com/questions/8498779/getpagesource-in-selenium-webdrivera-k-a-selenium2-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!