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'