robotframeworkselenium2library

Robot framework - How to specify default download location for Chrome?


I am trying to set default download location in Chrome. Below mentioned is the code:

*** Variables ***
${DOWNLOAD_DIRECTORY}  C:\\robot_framework\\Results
*** Keywords ***
Begin Web Test
    @{list} =  create list  disable-web-security      ignore-certificate-error
    ${args} =   create dictionary  args=${list}         download.default.directory=${DOWNLOAD_DIRECTORY}
    ${desired_caps} =   create dictionary  chromeOptions=${args}
    open browser  about:blank   ${BROWSER}  desired_capabilitis=${desired_caps}
    maximize browser window

When executed, code run fine however chrome is still downloading file into default directory. What change I need to bring in the code ?


Solution

  • This is a piece of code that I use:

    ${chromeOptions} =    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    ${prefs} =    Create Dictionary    download.default_directory=${downloadDir}
    Call Method    ${chromeOptions}    add_experimental_option    prefs    ${prefs}
    Call Method    ${chromeOptions}    add_argument    --lang\=${browserLocale}
    Call Method    ${chromeOptions}    add_argument    --headless
    Call Method    ${chromeOptions}    add_argument    --window-size\=1024,768
    Call Method    ${chromeOptions}    add_argument    --disable-gpu
    ${webdriverCreated} =    Run Keyword And Return Status    Create Webdriver    ${browserName}    chrome_options=${chromeOptions}
    Run Keyword Unless    ${webdriverCreated}    Create Webdriver    ${browserName}    chrome_options=${chromeOptions}
    

    I also had some issues when running downloads in headless Chrome. There's a workaround here if it's your case as well: How can I enable download a file using a headless chrome browser in robot framework?