一 元素定位
二 控制浏览器
1.操作浏览器
from selenium import webdriver dr = webdriver.Chrome("D:/soft/chromedriver.exe") dr.maximize_window() dr.get(‘https://www.baidu.com‘) dr.close()
from selenium import webdriver driver = webdriver.Chrome("D:/soft/chromedriver.exe") first_url = ‘https://www.baidu.com/‘ print("now access %s"%first_url) driver.get(first_url) second_url = ‘http://news.baidu.com/‘ print("now access %s"%second_url) driver.get(second_url) print("back to %s"%first_url) driver.back() print("forward to %s"%second_url) driver.forward() driver.quit()
from selenium import webdriver dr = webdriver.Chrome("D:/soft/chromedriver.exe") dr.maximize_window() dr.get(‘https://www.baidu.com‘) dr.refresh() # 模拟浏览器刷新 dr.quit()
2.简单元素操作