问题
I am using Robot Framework with PhantomJS (headless browser) and want to download a file. But PhantomJS is not having any desired Capabilities or options to set the preferences as we do in Chrome. Looking for any suggestions or other options to download a CSV file using PhantomJS with Robot Framework.
回答1:
As you highlighted that downloading files is not the issue. Below you'll find an example of Robot Script that starts Chrome in Headless mode.
*** Settings ***
Library Selenium2Library
Suite Teardown Close All Browsers
*** Test Cases ***
Headless Chrome - Open Browser
${chrome options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
${prefs} Create Dictionary credentials_enable_service=${false} # Verberg de sla wachtwoord op pop-up
Call Method ${chrome_options} add_experimental_option prefs ${prefs}
Call Method ${chrome options} add_argument start-maximized # Open de browser in gemaximaliseerd.
Call Method ${chrome_options} add_argument --headless
Call Method ${chrome_options} add_argument --disable-gpu
Call Method ${chrome_options} add_argument --window-size\=1920,1080
Create Webdriver Chrome chrome_options=${chrome options}
Go To http://cnn.com
Capture Page Screenshot
In case you want to run in headless mode in a Grid environment use the following example:
*** Settings ***
Library Selenium2Library
Suite Teardown Close All Browsers
*** Test Cases ***
Headless Chrome - Create Webdriver2
${chrome options} = Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${chrome_options} add_argument --window-size\=1920,1080
Call Method ${chrome options} add_argument --start-maximized
Call Method ${chrome options} add_argument --headless
Call Method ${chrome options} add_argument --disable-gpu
${options}= Call Method ${chrome_options} to_capabilities
Create Webdriver Remote command_executor=http://localhost:4444/wd/hub desired_capabilities=${options}
Go to http://cnn.com
Capture Page Screenshot
来源:https://stackoverflow.com/questions/47529897/how-to-download-a-file-with-phantomjs-using-robot-framework