0x00 config phantomJS1, under Windows platform
This method is used for automated testing by the browser.
1, download the Google Drive
Https://chromedriver.storage.googleapis.com/index.html
2. Put the extracted chromedriver.exe into the Chrome browser's installation directory.
3. Invoke the browser driver in the code to perform the automated operation.
' chromedriver Absolute Path ' = webdriver. Chrome (chromedriver) driver,get (URL)
2, in the Linux command line without interface
Using PHANTOMJS with Selenium, you can create a browser with no interface, so that it is up to us.
Configuration method:
1. Installing PHANTOMJS
Installation package: http://phantomjs.org/download.html, including Windows,mac os,linux version, choose the corresponding version of the download decompression can be
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
This error may be encountered when extracting tar.bz2 files with tar
Debian:/usr/src# Tar jxf linux-2.6.26.tar.bz2
Tar:bzip2:Cannot exec:no such file or directory
Tar:error isn't recoverable:exiting now
Tar:child returned status 2
Tar:error exit delayed from previous errors
Workaround:
This issue occurs when the Bzip2 tool is missing and the tool is installed.
Yum Install bzip2
0x02 Installation Selenium
Install Selenium
to here. The environment is well-equipped. The next step is to get the code.
0X03 Sample Code
= Webdriver. PHANTOMJS (executable_path='/bin/phantomjs/bin/phantomjs') #这里的executable_ Path fill your phantomjs driver.get ('http://www.xxxx.com') print Driver.titledriver.quit ()
Possible error messages:
Selenium.common.exceptions.WebDriverException:Message: ' Phantomjs ' executable needs to BES in PATH
This error is your PHANTOMJS save path is wrong, check to fill the path is the PHANTOMJS program save path.
Note that the Windows system is used here, and R is required in front of the path, referring to the code statement given.
Browser = Webdriver. PHANTOMJS (executable_path=r'C:\Users\lyh\Anaconda2\phantomjs-2.1.1-windows\bin\phantomjs.exe ')
Reference articles
48734389
76622776
Python SELENIUM+PHANTOMJS Automated test environment