我正在尝试使用python / selenium从此site下载PDF。当您从下拉菜单中选择一个选项时,它将显示一个PDF查看器。我已经找到了下载按钮,但是当我单击它时,什么也没发生。
Ps:“打印”按钮可以使用,但不能解决我的问题。
代码:
driver = webdriver.Chrome()
driver.implicitly_wait(2) #seconds
print('API | Acessando ' + row[i])
driver.get(row[i]) # row[i] is the website link
select = Select(driver.find_element_by_name('cmbGrupo'))
select.select_by_value('PDF|1653')
#PDF|1653 - Relatorio de Adminstracao
#PDF|412 - Notas Explicativas
wait = WebDriverWait(driver, 2)
# Select frame
report= driver.find_element(By.XPATH, ('//*[@id="iFrameFormulariosFilho"]'))
driver.switch_to.frame(report)
# Search second frame
pdfview = driver.find_element(By.XPATH, ('//*[@id="pdfViewer"]'))
driver.switch_to.frame(pdfview)
download = driver.find_element(By.XPATH, ('//*[@id="download"]'))
download.click()
答案 0 :(得分:0)
请使用afterclass或afternethod清除下载文件夹。
driver = webdriver.Chrome() driver.implicitly_wait(2)#秒 打印('API | Acessando'+行[i]) driver.get(row [i])#row [i]是网站链接 选择=选择(driver.find_element_by_name('cmbGrupo')) select.select_by_value('PDF | 1653')
wait = WebDriverWait(驱动程序,2)
report = driver.find_element(By.XPATH,('// * [@ id =“ iFrameFormulariosFilho”]'))) driver.switch_to.frame(report)
pdfview = driver.find_element(By.XPATH,('// [@ id =“ pdfViewer”]'))) driver.switch_to.frame(pdfview) 下载= driver.find_element(By.XPATH,('// [@ id =“ download”]'))) (((JavascriptExecutor)驱动程序).executeScript(“ arguments [0] .click();”,下载);