1. Operation and configuration python, in the previous article has been told before, is omitted here. . . .
2, the configuration and installation of selenium package python:
In the cmd window to perform the following: pip install -U selenium (note: either configured python_home, or execute the above command in the following python bin directory)
3, download ChromeDriver drive version:
http://chromedriver.storage.googleapis.com/index.html, unfortunately there is no 64-bit driver I want ah
Version 70.0.3538.110 (official version) (64)
Download a win32 try,
After extracting chrome exe files are copied to the directory C: \ ...... l \ Google \ Chrome \ Application
The C: \ ...... l \ Google \ Chrome \ Application directory to your environment variable path in
First check chrome version installed yourself
Then take a look at that URL note.txt according to the corresponding version of it, I'm here corresponds to 2.46, download win32 bit to try:
4. Set the system environment variable to the path of chrome added to the Path (specific steps below).
5. Enter test.py script:
import unittest
from selenium import webdriver
#print('hellow')
driver = webdriver.Chrome()
driver.get("http://www.baidu.com/")
driver.quit
6. Run:
7. The second python script
# _*_ coding:utf-8 _*_
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# Create instance of Chrome drive
driver = webdriver.Chrome()
driver.maximize_window () # maximize browser
driver.implicitly_wait (10) # wait time is provided implicitly 10s
# Launch a browser and navigate to the specified URL
driver.get("https://www.baidu.com/")
# Positioning name attribute is "wd" elements
input_text = driver.find_element_by_name("wd")
# Clear text input box, enter the text "selenium", then press Enter
input_text.clear()
input_text.send_keys("selenium")
input_text.send_keys(Keys.RETURN)
# Close the browser
driver.quit()
Operating results: If the above script is working correctly, will do the following: first open a Chrome browser, and then open the Baidu home page, enter "selenium" text in the search box and click Enter search results appear, and finally close the browser device
Reproduced in: https: //www.jianshu.com/p/57d89fb48dfb