简体   繁体   中英

How to get pagesource of particular part of a webpage in Selenium webdriver

I am trying to get pagesource of a specific part of the page. As we now that driver.getPageSource() will returns the entire source of the page.

My concern is - Is there any way to get HTML content between two web elements?

I managed to get some part of html by using the below method

driver.findElement(By.xpath(xpathOfParentElement)).getAttribute("outerHTML");

Later, I parsed the htmlString in the below method

org.jsoup.Jsoup.parse(htmlString).text();

Maven Dependency :

<dependency>
     <groupId>org.jsoup</groupId>
     <artifactId>jsoup</artifactId>
     <version>1.9.2</version>
</dependency>

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