• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

216
Vistas
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 3 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

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 3 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda