0

I recently got help with downloading a PDF file from a popup form, but now I would like to exit the form and for some reason I can't perform any actions after downloading the PDF.

I've tried ActionChains(driver).send_keys(Keys.ESCAPE).perform() and it doesn't exit the form. I've also tried driver.back() but that goes back one page and I would like to stay on the current page to continue downloading files.

Here's the code so far:

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

Trying to exit out of the following popup form: enter image description here

Glenn G.
  • 419
  • 3
  • 7
  • 18
  • You can use expected conditions `from selenium.webdriver.support import expected_conditions as EC` to check for alerts, switch to them and accept them – G. Anderson Dec 03 '18 at 18:43
  • I'm trying to understand how expected_conditions would work in this situation. I've tried checking for alerts but it's not working. Could you provide a code example of how you would apply expected_conditions to this problem? – Glenn G. Dec 03 '18 at 19:43
  • This is just one avenue to check, it may not be an alert message.`if EC.alert_is_present():\alert=driver.switch_to.alert\alert.accept()` – G. Anderson Dec 03 '18 at 20:29
  • Getting `WebDriverException: Message: chrome not reachable. `--> alert = driver.switch_to.alert – Glenn G. Dec 03 '18 at 20:57

1 Answers1

1

I had updated my answer here, but incase you missed it,

Try this to close the popup:

driver.switch_to.default_content()
driver.find_element_by_xpath('//*[@id="ctl00_GenericPopupSizeable_InnerPopupControl_HCB-1"]/img').click()

Explanation: The close button of popup is not in the iframe where download link is seen, so we need to go back to main content and then click on popup close button.

Kamal
  • 2,384
  • 1
  • 13
  • 25