Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda