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 file or directory: ‘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 not match 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