Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
selenium query: javascript equivalent find.element (by.xclass)

I have to find in an html page a id tag which is embedded in a class tag.

driver.find_element(By.XPATH, "//div[@class='Content warning']/p").get_attribute("id")

enter image description here

I made it worked with selenium, the instruction is:

driver.find_element(By.XPATH, "//div[@class='Content warning']/p").get_attribute("id"))
 

Nonetheless, despite the fact it works perfectly, it is a bit slow, and I would like to try a javascript code injected directly into the page (with a code injector)

Therefore, I am looking for the equivalent of the selenium instruction in javascript.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

In javascript that would be:

driver.execute_script('''
  return document.querySelector('div[class="Content warning"] > p').id
''')
about 4 years ago · Juan Pablo Isaza Denunciar

0

While @pguardiario seems correct, you could do this as well in Python to execute the JS code (and can use Selenium get_attibute)

content_warning = driver.execute_script('''
  return document.querySelector('div[class="Content warning"] > p')
''')
content_warning.get_attribute('id')
about 4 years ago · Juan Pablo Isaza 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda