Ubuntu python3.41. Install Selenium, PIP installation
Pip Install Selenium
2.selenium version 2.53.x
Try to download the selenium3 from the official website, but firefox to install the new geckodriver, the change back to 2.53.x.
The next study will be supplemented.
3. Start the sample exercise
A QQ Mailbox Login program was tested:
#-*-coding:utf-8-*- fromSeleniumImportWebdriver fromSelenium.webdriver.common.keysImportKeysImportTimedriver=Webdriver. Firefox () Driver.get ("http://mail.qq.com/")ifU"Login" inchDriver.title:Print("Login") Driver.switch_to.frame ("Login_frame") Elem= driver.find_element_by_id ('u') Elem.clear () Elem.send_keys (user name) Elem= driver.find_element_by_id ('P') Elem.clear () Elem.send_keys (password+Keys.return) driver.switch_to.default_content ()assertU"QQ" inchDriver.titlePrint(U'Login on it! ') Time.sleep (90) Driver.close ()
View Code
At first the user name password find_element can not find, and later found in an IFRAME, using switch to frame after the smooth find_element.
Driver.switch_to.frame ("login_frame")
This is a small trap for selenium, and after it is done, almost all of the element has a method to check.
4. Proxy Verification
Firefox often pops up the verification window after using the auto agent. It's annoying, and I can't find a way to get selenium off.
Then installs the Firefox plugin Auto Auth, solves. :)
Selenium is very convenient to use, it is also quick to get started ...
Python Selenium first entry