Python SELENIUM+PHANTOMJS Automated test environment

Source: Internet
Author: User
Tags bz2

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.