Python Selenium挂起。单击while循环中的()
我正在尝试从该网站下载所有电子表格,该网站要求我单击该项目,然后单击下载按钮。电子表格都使用相同的id保存,每个id后面的数字都会增加。我试图使用while循环来解决这个问题,但我不确定这是否是最好的方法Python Selenium挂起。单击while循环中的(),python,selenium,selenium-webdriver,selenium-chromedriver,Python,Selenium,Selenium Webdriver,Selenium Chromedriver,我正在尝试从该网站下载所有电子表格,该网站要求我单击该项目,然后单击下载按钮。电子表格都使用相同的id保存,每个id后面的数字都会增加。我试图使用while循环来解决这个问题,但我不确定这是否是最好的方法 i = 0 while i < 13: device = 'ctl00_LeftBarContent_lvLeftPanel_lbDevices_i' + str(i) deviceElement = WebDriverWait(driver, 1
i = 0
while i < 13:
device = 'ctl00_LeftBarContent_lvLeftPanel_lbDevices_i' + str(i)
deviceElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(device))
deviceElement.click()
time.sleep(2)
downloadXpath = "ctl00_LeftBarContent_lvLeftPanel_btnDownload"
WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(downloadXpath)).click()
time.sleep(2)
i += 1
i=0
而我<13:
设备='ctl00_LeftBarContent_lvLeftPanel_lbDevices_i'+str(i)
deviceElement=WebDriverWait(驱动程序,10).until(lambda驱动程序:驱动程序.通过\u id查找\u元素(设备))
deviceElement.单击()
时间。睡眠(2)
downloadXpath=“ctl00\u LeftBarContent\u lvLeftPanel\u btnDownload”
WebDriverWait(driver,10)。直到(lambda driver:driver.find_element_by_id(downloadXpath))。单击()
时间。睡眠(2)
i+=1
目前,代码运行到点击下载按钮,文件下载,然后它似乎挂在按钮上,最终超时。我正在使用chrome驱动程序
谢谢 此评论仅针对您的缩进。要么缩进i,要么在i之后缩进所有代码 不正确的示例“Hello World”:
i = 0
while i < 13:
print 'hello world'
i+=1
'error unexpected indent'
i = 0
while i < 13:
print 'hello world'
i+=1
'Hello world'
'Hello world'
'Hello world'
'Hello world'
etc...
i=0
而我<13:
打印“hello world”
i+=1
“意外缩进错误”
正确示例“Hello World”:
i = 0
while i < 13:
print 'hello world'
i+=1
'error unexpected indent'
i = 0
while i < 13:
print 'hello world'
i+=1
'Hello world'
'Hello world'
'Hello world'
'Hello world'
etc...
i=0
而我<13:
打印“hello world”
i+=1
“你好,世界”
“你好,世界”
“你好,世界”
“你好,世界”
等
因此,对于您的问题,请正确缩进问题,然后重试。如果您仍然有问题,请在每个命令之前和之后插入一些print语句,以查看您遇到的问题。只是猜测一下,但您可能需要切换帧,然后在第一次下载完成后关闭帧。只添加结果,而不提供教程。