Interacting with pop-up boxes using selenium in python

前端 未结 2 2041
眼角桃花
眼角桃花 2021-02-06 18:12

I\'m trying to use the Selenium module in python to generate a text list from one website, save it in a directory, and browse to that text list on another site to submit it.

2条回答
  •  悲哀的现实
    2021-02-06 18:47

    The popups you see are not regular popups that can be interacted with using switch_to. These popups are system dialogs and cannot be automated using selenium.

    Usually people avoid having these dialogs shown in the first place by tweaking browser preferences, e.g.:

    • downloading file using selenium
    • Access to file download dialog in Firefox
    • How to download a file using Selenium's WebDriver?

    For uploading, usually you can find the appropriate input element and send keys to it with a path to the file:

    • How to upload file ( picture ) with selenium, python
    • How to upload files into file inputs? (python-selenium docs)

    Let me know if your case cannot be solved by using the answers in the links I've attached.


    As for your first, "download file automatically" problem, you just need to set a correct content-type:

    profile.set_preference('browser.helperApps.neverAsk.saveToDisk', "application/xml,text/xml")
    

    Second problem fix (upload part):

    driver.find_element_by_name("input_product_list").send_keys(textpath)
    driver.find_element_by_name('include_sr').click()
    driver.find_element_by_id('submit').click()
    

提交回复
热议问题