Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 使用Python Selenium运行循环_Python 3.x_Selenium_Selenium Webdriver - Fatal编程技术网

Python 3.x 使用Python Selenium运行循环

Python 3.x 使用Python Selenium运行循环,python-3.x,selenium,selenium-webdriver,Python 3.x,Selenium,Selenium Webdriver,我正在尝试在循环中运行driver.execute_脚本,以在自动化过程中获取一些值,但是该方法似乎不起作用。只是需要聪明人的帮助,如何克服这种情况。我正在为这个输入一个示例代码 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 cod

我正在尝试在循环中运行driver.execute_脚本,以在自动化过程中获取一些值,但是该方法似乎不起作用。只是需要聪明人的帮助,如何克服这种情况。我正在为这个输入一个示例代码

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)
输出如下:它运行整个脚本barring driver.execute\u脚本

但是如果我只在IPython控制台中运行脚本

[11]中:驱动程序。执行脚本(script1)

输出

出[11]:“”

它起作用了

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
print(driver.execute_script(script1))