Python - Select "Save link as" and save a file using Selenium
<p>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.</p>

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

<pre><code>    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();
</code></pre>

<p>Kindly suggest how to download the file using these 3 steps. Thanks</p>

<p>As per java you can use following code for clicking save as link and click save in new window</p>

<pre><code>try {
          Robot bot = new Robot();
            //location of link on your page
            bot.mouseMove(5, 12);    
            //instigate right click of mouse
            bot.mousePress(InputEvent.BUTTON1_MASK);
            bot.mouseRelease(InputEvent.BUTTON1_MASK);
            Thread.sleep(1000); 
            /*repeatedly press down arrow untill you reach save as link in context menu*/
            bot.keyPress(KeyEvent.VK_DOWN);
            Thread.sleep(1000);
            bot.keyPress(KeyEvent.VK_DOWN);
            Thread.sleep(1000);
            bot.keyPress(KeyEvent.VK_DOWN);
            Thread.sleep(1000);
            bot.keyPress(KeyEvent.VK_DOWN);
           //press enter to select save as link
            Thread.sleep(1000);
            //press enter to press save button on new window
            bot.keyPress(KeyEvent.VK_ENTER);                
            Thread.sleep(1000);
            bot.keyPress(KeyEvent.VK_ENTER);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
</code></pre>

<p>As per your question you need python code so you can convert this code in python by using this link <a href="https://pypi.python.org/pypi/py_robot/0.1" rel="nofollow">https://pypi.python.org/pypi/py_robot/0.1</a></p>

python selenium