設定網頁下載路徑 - daniel-qa/RobotFramework GitHub Wiki

設定網頁下載路徑

Set Chrome Options download.default_directory=${DOWNLOAD_DIR}

  • Example
*** Settings ***
Library           SeleniumLibrary

*** Variables ***
${DOWNLOAD_DIR}   /path/to/your/download/directory

*** Test Cases ***
Set Download Location

    Open Browser    http://example.com    Chrome
	
    Set Chrome Options    download.default_directory=${DOWNLOAD_DIR}
	
    Go To    http://example.com/download
    Click Element    //a[@id='downloadButton']
    # 等待下載完成,這取決於你的網頁和網速
    Wait Until Keyword Succeeds    2 minutes    1 second    [Return]    File Should Exist    ${DOWNLOAD_DIR}/downloaded_file.txt
    Close Browser