【发布时间】:2018-12-03 18:38:30
【问题描述】:
我最近在从弹出表单下载 PDF 文件方面获得了帮助,但现在我想退出表单,但由于某种原因,我在下载 PDF 后无法执行任何操作。
我试过ActionChains(driver).send_keys(Keys.ESCAPE).perform() 并没有退出表单。我也尝试过driver.back(),但这会回到一页,我想留在当前页面继续下载文件。
这是目前为止的代码:
options = webdriver.ChromeOptions()
prefs = {"download.default_directory":"C:/Users/gille/Documents/SJ Webscraping/data","plugins.plugins_list":[{"enabled":False,"name":"Chrome PDF Viewer"}]}
options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(options=options)
driver.get("https://www.southtechhosting.com/SanJoseCity/CampaignDocsWebRetrieval/Search/SearchByElection.aspx")
driver.find_element_by_xpath('//*[@id="ctl00_DefaultContent_ASPxRoundPanel1_btnFindFilers_CD"]').click()
driver.find_element_by_xpath('//*[@id="ctl00_GridContent_gridFilers_DXCBtn0"]').click()
driver.find_elements_by_xpath('//td[@class="dxgvCommandColumn_Glass dxgv"]//img[@title="View Form"]')[0].click()
driver.switch_to.frame(driver.find_element_by_tag_name('iframe'))
a = driver.find_element_by_link_text("Click here")
ActionChains(driver).key_down(Keys.CONTROL).click(a).key_up(Keys.CONTROL).perform()
#insert exit sequence here
【问题讨论】:
-
您可以使用预期条件
from selenium.webdriver.support import expected_conditions as EC来检查警报,切换到它们并接受它们 -
我试图了解 expected_conditions 在这种情况下是如何工作的。我试过检查警报,但它不起作用。您能否提供一个代码示例,说明如何将 expected_conditions 应用于此问题?
-
这只是一种检查方式,可能不是警报消息。
if EC.alert_is_present():\alert=driver.switch_to.alert\alert.accept() -
获取
WebDriverException: Message: chrome not reachable.--> alert = driver.switch_to.alert
标签: python selenium selenium-chromedriver