Pop Up Window with Selenium

人走茶凉 提交于 2019-12-25 01:03:00

问题


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

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

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



回答2:


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)


来源:https://stackoverflow.com/questions/45595329/pop-up-window-with-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!