Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
Java selenium grabbing entire html contents of the element

I was wondering if there was a way to get the entire html code between two tags of an element, along with the element tag then store it in a string.

Lets say I use the following to create a list of web elements, then fill the list with all the 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 3rd web element, it prints only the tags name, as it should:

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

so it prints the paragraph element "p" or "input" for example if it is the 3rd web element stored

But I was wondering if its possible to get the entire html code line for the web element and print it rather then only the tag name "p" for example?

e.g.

<p> some text </p>

Is there some way to accomplish this?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can read outerHTML attribute to get the entire element.

element.getAttribute("outerHTML");

Or in your case:

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

Hope it helps!

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!