1. 程式人生 > >selenium+python3.6學習——第一個指令碼

selenium+python3.6學習——第一個指令碼

在哪下載,為什麼下載,參考

http://selenium-python.readthedocs.io/installation.html     1.3Drivers.

2. 解壓geckodriver,。新增環境變數:(為什麼新增,同樣參考上面的官方,我都是按照官方教程做的)

GECKODRIVER

E:\...\geckodriver-v0.15.0-win64

在path中新增:%GECKODRIVER%

3. 編寫程式碼:以下是官方提供的一個開啟瀏覽器,搜尋 ,關閉的指令碼,把這個指令碼儲存,起個名字:python_org_search.py

http://selenium-python.readthedocs.io/getting-started.html

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found."
not in driver.page_source driver.close()
4.執行,在當前目錄下開啟命令列,執行python python_org_search.py


5.遇到這個問題:Missing 'marionetteProtocol' field in handshake,這個問題後來查了一下,是我的firefox版本太低了,我的是38.升級到48以後正常。