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

后端 未结 2 617
心在旅途
心在旅途 2020-12-11 04:32

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

相关标签:
2条回答
  • 2020-12-11 04:36

    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);
    
    0 讨论(0)
  • 2020-12-11 04:50

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

    link to java doc

    0 讨论(0)
提交回复
热议问题