0

I currently have a script that will log on to my company's wiki, visit a page, and select a download to pdf option available on the page. However, when this option is chosen, this dialogue box

dialogue

pops up asking me to tell Firefox what to do with it. I just need selenium to interact and hit the "ok" button.

I'm not sure how to inspect this window for elements, and am need of direction. Any documentation helps.

from splinter import Browser
browser = Browser()
browser.visit('https://company.wiki.com')
browser.find_by_id('login-link').click()
browser.fill('os_username', 'user')
browser.fill('os_password', 'pass')
browser.find_by_name('login').click()
browser.visit('https://pageoncompany.wiki.com')
browser.find_by_xpath('//*[@id="navigation"]/ul/li[4]').click()
browser.find_by_id('action-export-pdf-link').click()
Bill Bell
  • 21,021
  • 5
  • 43
  • 58
  • 1
    Possible duplicate of [download and save multiple csv files using selenium and python from popup](https://stackoverflow.com/questions/45097302/download-and-save-multiple-csv-files-using-selenium-and-python-from-popup) – undetected Selenium Aug 09 '17 at 15:55
  • Is this an alert or a popup window? Either way you need to use the "SwitchTo()". Let me know what it is and I'll be more than happy to help you further. – IamBatman Aug 09 '17 at 15:59
  • I believe it is a pop up since I tried to use driver.switch().alert().accept() and it didnt work –  Aug 09 '17 at 16:57
  • A few questions have been asked and answered here on SO. You can view them by googling for **selenium dialog box**. – Bill Bell Aug 09 '17 at 19:09
  • Try this: https://stackoverflow.com/questions/1176348/access-to-file-download-dialog-in-firefox – IamBatman Aug 09 '17 at 19:53
  • This does not work. I set pdf's to automatically download, but the session created by splinter ignores the preference. –  Aug 10 '17 at 12:11

2 Answers2

1

I was able to set the preferences through the web browser, then call my profile:

browser = Browser('firefox', profile=r'C:\Users\craab\AppData\Roaming\Mozilla\Firefox\Profiles\0lot9hun.default')
0

You can set preferences in order to prevent coming of download popup ad download it to pre-defined folder.

fp = webdriver.FirefoxProfile()

fp.set_preference("browser.download.folderList", 2)  # custom folder as set by repo
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.dir", <download_folder_path>)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", content_type)
# Enable auto download, Avoid popup during downloads
fp.set_preference("browser.download.panel.shown", False)
fp.set_preference("browser.helperApps.neverAsk.openFile", content_type)

driver = webdriver.Firefox(fp)
SunilThorat
  • 1,672
  • 2
  • 13
  • 15
  • Very helpful! Now is there a certain way I should call this to start the download, or will it work with my code as is? –  Aug 10 '17 at 12:41
  • @ChaseRaab You just need to click on download link, file will saved in mentioned download path. – SunilThorat Aug 10 '17 at 13:14
  • The point of the script is that I won't have to click anything though. –  Aug 10 '17 at 13:33