Java selenium captures all html element content

I was wondering if there is a way to get all the html code between two element tags along with the element tag and then save it in a string.

Suppose I use the following to create a list of web elements, and then populate the list with all web elements.

List<WebElement> element = driver.findElements(By.xpath("//*"));
//Some for loop after this to access each value

If I use the following to get the third web element, it prints only the tag name, as it should:

System.out.println(element.get(3).getTagName()); 

therefore, it prints the paragraph element "p" or "input", for example, if it is the third web element saved

But I was wondering, is it possible to get the entire line of html code for a web element and print it, and not just the tag name “p”, for example?

eg.

<p> some text </p>

Is there any way to do this?

+4
1

outerHTML, .

element.getAttribute("outerHTML");

:

System.out.println(element.get(3).getAttribute("outerHTML")); 

, !

+1

Source: https://habr.com/ru/post/1673650/


All Articles