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

192
Views
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 answers
Answer question

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 Report

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 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!