【发布时间】:2020-05-21 16:25:03
【问题描述】:
程序如何运作? 使用循环下载多个文件,在您选择它在带有下载图标的 iframe 中打开的文档后,按下文件下载后,程序关闭 iframe 并重新启动循环,选择一个新项目等等,问题在打开 iframe 并选择它后发生在第二个循环中,它无法找到下载图标。 它在同一个 iframe 中具有相同 xpath 的相同图标如何在第二次尝试中找不到?
def DownloadCurrentApprovals():
table=driver.find_element_by_xpath('//*[@id="ctl00_MainContent_ApprovalGridViewControl_ApprovalGridViewInfo_ctl00"]')
i = 0
for tr in table.find_elements_by_tag_name("tr"):
#selecting the item to be printed
robo = driver.find_element_by_xpath('//*[@id="ctl00_MainContent_ApprovalGridViewControl_ApprovalGridViewInfo_ctl00__{}"]'.format(i)).click()
#press the download icon which will open the iframe
robo = driver.find_element_by_xpath('//*[@id="ctl00_MainContent_ApprovalGridViewControl_ApprovalGridViewInfo_ctl00_ctl02_ctl00_ApprovalRadToolBar"]/div/div/div/ul/li[2]/a/span/span/span/span').click()
driver.implicitly_wait(10)
#get the frame
frame = driver.find_element_by_xpath('//*[@id="RadWindowWrapper_ctl00_MainContent_RadWindowApprovalReport"]/table/tbody/tr[2]/td[2]/iframe')
driver.switch_to.frame(frame)
#pressing the download icon inside the iframe
element = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="ReportViewer_ReportToolbar_PrintGr_Print_Button"]/tbody/tr/td/input[1]')))
#switching to close the iframe
driver.switch_to.default_content()
robo = driver.find_element_by_xpath('//*[@id="RadWindowWrapper_ctl00_MainContent_RadWindowApprovalReport"]/table/tbody/tr[1]/td[2]/table/tbody/tr/td[3]/ul/li[5]/a').click()
i+=1
错误 --raise TimeoutException(消息、屏幕、堆栈跟踪) selenium.common.exceptions.TimeoutException:消息:
【问题讨论】: