- 环境
Windows
- 前提:
1. python已正常安装
2. selenium已正常安装。 如果没安装,会报:ImportError: No module named 'selenium'
(参考:https://blog.csdn.net/u011151028/article/details/50338347)
- 实例:
参考:https://blog.csdn.net/u011541946/article/details/68484368
# coding=utf-8 import time from selenium import webdriver #driver = webdriver.Chrome() driver = webdriver.Firefox() #打开chrome,如果没有安装chrome,换成webdriver.Firefox() #driver.maximize_window() # 最大化浏览器窗口 #driver.implicitly_wait(8) # 设置隐式时间等待 #time.sleep(2) print ("1.打开浏览器...") driver.get("http://www.baidu.com") print ("2.打开首页...")
print ("3.输入用户名密码...")
driver.find_element_by_xpath("//*[@id='app']/div/div/form/div[1]/input").send_keys("XXXXXX")
driver.find_element_by_xpath("//*[@id='app']/div/div/form/div[2]/input").send_keys("XXXXXX")
#点击登录
print ("4.点击登录...")
driver.find_element_by_xpath("//*[@id='app']/div/div/form/button").click()
- 执行
cmd下,执行脚本
问题1:使用webdriver.Firefox()时报错:
Message: 'geckodriver' executable needs to be in PATH.”
解决办法:需下载deckodriverV0.15
参考:
https://www.cnblogs.com/yousuosiyss/p/6882420.html
问题2:使用webdriver.Firefox()时报错: Unsupported Marionette protocol version 2, required 3
解决办法:需使用chrome 47.
参考:
https://www.cnblogs.com/v5captain/p/6239081.html?utm_source=itdadao&utm_medium=referral