我正在尝试在Chrome中设置默认的下载位置。下面提到的是代码:
*** 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
执行后,代码运行良好,但是chrome仍将文件下载到默认目录中。我需要输入代码进行哪些更改?
答案 0 :(得分:1)
这是我使用的一段代码:
${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}
在无头Chrome中运行下载时,我也遇到了一些问题。如果您也遇到这种情况,这里有一种解决方法:How can I enable download a file using a headless chrome browser in robot framework?