user8162541
user8162541

Reputation:

Pop Up Window with Selenium

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()

Upvotes: 0

Views: 617

Answers (2)

user8162541
user8162541

Reputation:

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')

Upvotes: 1

SunilThorat
SunilThorat

Reputation: 1748

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)

Upvotes: 0

Related Questions