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

186
Views
How to pass hundreds of lines of js code to Selenium

I'm really tired of the stupid library selenium. If you want to pass js code to Selenium, use:

`js = "JS code here"
driver.excute_script(js)`

However, my js code has multiple lines, which looks like below:

setTimeout(function(){
l = document.getElementsByClassName("test-option");
    for(const a in l){if(l[a]==undefined || l[a]==null)
        continue

    if(l[a].innerText !=undefined && l[a].innerText.includes("Miracle"))
    {
        l[a].click();
    }
}
}, 2000);

When you delete the new line char in each line and put them together with single or double quotes. Selenim starts to spark. Is there any better way to pass the js string? Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Aside from being messy that shouldn't be a problem:

driver.execute_script("""
  setTimeout(function(){
    l = document.getElementsByClassName("test-option");
      for(const a in l){if(l[a]==undefined || l[a]==null)
        continue

      if(l[a].innerText !=undefined && l[a].innerText.includes("Miracle"))
      {
        l[a].click();
      }
    }
  }, 2000)
""")
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!