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

160
Views
Running a "for" loop in JavaScript through Python-Selenium?

I use Javascript to collate data from an HTML page via Selenium; however, I cannot run the Javascript portion from my computer via Selenium/py cause Python only offers the driver.execute_script('string of a script'), whereas I have a multi-line for loop which won't execute with these commands.

The loop:

for (let i = 0; i < Values.length; i++) {
    if (Values[i].getAttribute('automation-id') === 'contact-wealth-manager') {
        ele = Values[i]
    }
}

As you can test, this won't work with the standard "driver.execute_script("let value = '';")

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

0

To execute the multiline loop Javascript you need to pass the script as an argument to execute_script() method as follows:

driver.execute_script("""
    for (let i = 0; i < Values.length; i++) {
        if (Values[i].getAttribute('automation-id') === 'contact-wealth-manager') {
            ele = Values[i]
        }
    }
""")
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!