简体   繁体   中英

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

如何使用带有Java的Selenium WebDriver查看“标题”和“元”标签之间的页面来源?

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

link to java doc

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM