Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

38
Vistas
Get text value from especific class in web site

I want to know if it is possible to go to a site and retrieve the text of an element

i think something like

a = page("www.site.com")
b = a.getElementByClass("name")
console.log(b.text)

this is possible?

7 months ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Yes. It's called the innerText property. See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText

7 months ago · Juan Pablo Isaza Denunciar

0

That depends,

If you want to get the innerText of the elements, then

let elements = document.getElementsByClassName("YourClassName");
for(let i=0;i<elements.length; i++){
  /*doSOmething*/
   console.log(elements[i].innerText);
}

Many elements may have same className. So, if you want to access some specific Element, then you should either know the index of the element or you need to use id for the element.

let element = document.getElementById("YourElementId");
  /*doSOmething*/
console.log(element.innerText);
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos