2

I am trying to run driver.execute_script inside a loop to fetch some values during automation, however it appears that this method is not working. Just needed some help from bright minds how to get past this scenario. I am putting one sample code for this.

from selenium import webdriver
cURL = "http://google.com"
driver = webdriver.Chrome()
driver.get(cURL)
for i in range(0, 3):
    print(i) ## To check if the code ran till here
    for x in range(0, 3):
        print(x) ## To check if the code ran till here
        script1 = "return document.URL"
        print(script1) ## To check if the code ran till here
        driver.execute_script(script1)

The output is as follows it runs the entire script barring driver.execute_script

0
0
return document.URL
1
return document.URL
2
return document.URL
1
0
return document.URL
1
return document.URL
2
return document.URL
2
0
return document.URL
1
return document.URL
2
return document.URL

However if I only run the script in IPython Console

In [11]:driver.execute_script(script1)

Output

Out[11]: 'https://www.google.com/?gws_rd=ssl'

1 Answer 1

2
print(driver.execute_script(script1))

It works

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.