Brief introduction:
Previously, PHANTOMJS was used for automated testing without interface mode, or to crawl some dynamic pages.
However, after the recent selenium update, the ‘Selenium support for PhantomJS has been deprecated, please use headless ‘
prompt does not support PHANTOMJS, please use headless mode.
Well, let's continue using Firefox Chrome's headless mode.
One: Version Confirmation
1.windows down
Selenium 3.9.0
I am using this version of selenium and have been prompted to stop support. You can find this article and prove that your version is not too low.
Firefox 58.0.2 (64-bit)
This is a long-term support version, not the latest version, some features seemingly unstable, and often updated.
Chrome version 64.0.3282.119 (official version) (64-bit)
This is easy to follow the application of the housekeeper upgrade, after all, not even on the Google upgrade server.
Python 3.6.3 AMD64
This is indeed the version.
2.linux
Not tested yet. Deploy a Linux project in a few days and share the version with you.
Two: Firefox headless mode
fromSeleniumImportwebdriveroptions=Webdriver. Firefoxoptions () options.set_headless ( )#options.add_argument ('-headless ')Options.add_argument ('--disable-gpu') Driver=webdriver. Firefox (firefox_options=options) Driver.get ('http://httpbin.org/user-agent') Driver.get_screenshot_as_file ('Test.png') Driver.close ()
Instantiate firefoxoptions
With Set_headless
or add_headless
When instantiating a Firefox browser, add parameters firefox_options=options
That's all you can do.
The phrase '--DISABLE-GPU ' is disabling GPU acceleration.
Three: Chrome headless mode
from selenium import webdriveroptions =webdriver. Chromeoptions () options.set_headless () # Options.add_argument ('--headless ') options.add_argument ( " --disable-gpu " ) driver =webdriver. Chrome (Options=options) driver.get ( " Span style= "COLOR: #800000" >http://httpbin.org/user-agent " Driver.get_screenshot_as_file ( " test.png " ) driver.close ()
Same as Firefox above.
Selenium (vi) Headless CHROME/FIREFOX--PHANTOMJS stop support, use no interface mode.