【发布时间】:2021-12-30 10:50:51
【问题描述】:
我创建了一个程序,该程序将转到某个网站,输入一个作品集编号,然后进入页面并单击以生成 PDF。我现在需要将该 pdf 下载到指定路径。
我已经能够生成 PDF。但是我正在发送密钥,但它不起作用。
用于转到页面并生成 pdf 的代码:
options = webdriver.ChromeOptions()
options.headless = True
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
driver.implicitly_wait(10)
#set chromedriver.exe path
driver = webdriver.Chrome('driver/chromedriver.exe')
driver.maximize_window()
#driver.execute_script("document.body.style.zoom='75%'")
#Launch Url
driver.get('https://gisweb.miamidade.gov/SPTXLienLetters/')
driver.find_element_by_xpath('//*[@id="divSplashScreenContent"]/table/tbody/tr[2]/td/div/div').click()
#Take data from config file
file = open('configsa.txt')
lines = file.readlines()
folio_number = lines[0]
driver.implicitly_wait(30)
#Find elements and take snapshots
elementID = driver.find_element_by_xpath('//*[@id="txtAddress"]')
elementID.send_keys(folio_number)
elementID = driver.find_element_by_xpath('//*[@id="tdDivAddress"]/table/tbody/tr/td[2]').click()
elementID = driver.find_element_by_xpath('//*[@id="trOtherAppLinks"]/td/div/span[1]/a').click()
我尝试使用以下代码进行保存,但无济于事:
action_chains = ActionChains(driver)
action_chains.send_keys(Keys.CONTROL).send_keys('s').perform()
或
saveas = ActionChains(driver).key_down(Keys.CONTROL).send_keys('S').key_up(Keys.CONTROL).send_keys('MyDocumentName').key_down(Keys.ALT).send_keys('S').key_up(Keys.ALT)
以上代码均无效。有人可以帮忙吗?
【问题讨论】:
-
configsa.txt文件中的数据是什么?我们需要一些 folio_number 数据以用于调试
标签: python selenium pdf selenium-webdriver