Setting selenium to use custom profile, but it keeps opening with default

后端 未结 3 1995
悲哀的现实
悲哀的现实 2020-12-01 06:20

I am trying to use python and selenium to automate some tasks in firefox. When I download a file, that pop up comes up asking if you want to open or save, and a check box fo

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 06:51

    Error: fp.set_preference("browser.download.dir",getcwd()) NameError: name 'getcwd' is not defined

    getcwd() is not defined. So I assume you want the getcwd from the os module:

    • http://docs.python.org/library/os.html

    add: import os , and then invoke with os.getcwd().

    or you could just add the import for this function: from os import getcwd

    your example with the proper imports included:

    import os
    from selenium import webdriver
    
    profile = webdriver.FirefoxProfile()
    profile.set_preference('browser.download.folderList', 2)
    profile.set_preference('browser.download.manager.showWhenStarting', False)
    profile.set_preference('browser.download.dir', os.getcwd())
    profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/csv/xls')
    driver = webdriver.Firefox(profile)
    

提交回复
热议问题