Installing the Python+selenium+firefox learning environment under CENTOS7

Source: Internet
Author: User

Selenium an automated test tool. It supports the mainstream interface browser such as Chrome,safari,firefox, if you install a Selenium plugin in these browsers, then you can easily implement the Web interface testing.

So, you have to use selenium you have to have a browser first (most people do not say this, a little pit!). ), whether it's Chrome or Firefox, you have to have one.

Installed after the browser, holding a happy mood with PIP3 installed selenium, in Pyhton interactive mode directly import Webdriver, create Webdriver object reported the following error:

1 No such fileordirectory: ‘geckodriver‘

What the hell is going on here? Also need to install the browser driver files .... , download the following page,

1 https: / / Code class= "Python plain" >github.com / SELENIUMHQ / selenium / blob / master / py / docs / source / index.rst

Remember to download the corresponding driver, chrome can not use Firefox,firefox or chrome, if the driver version is wrong, will report the error that can not be executed, as follows

1 OSError: [Errno 8] Exec format error

Why not get all the drivers together? I don't understand.

To extract the downloaded driver files to/usr/bin, or/usr/local/bin below, also in your environment variables in, how you directly modify path, I think it is OK, as long as you can find it.

Here, the feeling should be OK, no, create the object is no problem, but a visit URL, and error .....

1 geckodriver.log Error: GDK_BACKEND does notmatch available displays

From the Geckodriver.log to see the error message, need a display, originally wanted to command line, but prompted to need a matching display. After going to Google search to get, need to create a virtual display.

Install the following software to create:

Yum install Xvfb libxfont xorg-x11-fonts*pip3 install  pyvirtualdisplay

Jump out of these pits, and finally can be used normally, the test code is as follows:

1From seleniumimport Webdriver 2 from pyvirtualdisplay import Display 3 4 5 display = Display (visible=0, size= (800,6006 display.start () 7 driver = webdriver. Firefox (8 driver.get ( " Span style= "COLOR: #800000" >http://www.baidu.com ") Span style= "COLOR: #008080" >9 print driver.page_source      

This is finally a smooth print out the HTML statement, smooth out of the big hole!

Installing the Python+selenium+firefox learning environment under CENTOS7

Related Article

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.