[Python] Python - Select "Save link as" and save a file using Selenium

Discussão em 'Python' iniciado por Stack, Setembro 7, 2025.

  1. Stack

    Stack Membro Participativo

    Newbie: There are different files on a webpage, which can be downloaded as follows: 1. Right click on a file link 2. Select "Save link as" 3. Click "Save" button on the new window.

    I tried the following code(for first 2 steps), but it is not working:

    from selenium import webdriver
    from selenium.webdriver import ActionChains
    from selenium.webdriver.common.keys import Keys
    import time

    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('www.example.com')
    time.sleep(1)

    driver.find_element_by_link_text("MarketFiles/").click()


    actionChains = ActionChains(driver)

    download_file = "Market_File1.csv"
    link = driver.find_element_by_link_text(download_file)

    actionChains.context_click(link).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.RETURN).perform();


    Kindly suggest how to download the file using these 3 steps. Thanks

    Continue reading...

Compartilhe esta Página