selenium python 启动Firefox

我的火狐浏览器版本是最新的:

selenium python 启动Firefox

下载geckodrive:https://github.com/mozilla/geckodriver/releases/

selenium python 启动Firefox

下载完后将exe文件放到这里“D:\firefox”即firefox安装目录的快捷方式所在的文件夹,同时将这个路径放到path中:

D:\Python3\Scripts\;D:\Python3\;D:\Python36-32\Scripts\;D:\Python36-32\;%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;C:\strawberry\c\bin;C:\strawberry\perl\bin;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\Program Files\OpenVPN\bin;c:\windows\system32;E:\Python;D:\Python36-32;D:\Python3;E:\python\python3;C:\Users\Administrator\AppData\Local\Google\Chrome\Application;D:\firefox

重启下PyCharm可以调用了:

 import time

 from selenium import webdriver
import os username = "jiangpr_ok@163.com" # 请替换成你的用户名
password = "d123456789d" # 请替换成你的密码 # driver = webdriver.Chrome() # 选择Chrome浏览器
driver = webdriver.Firefox()
driver.get(url='http://vip.jd.com') # 打开京东会员网站
time.sleep(1) driver.find_element_by_link_text('账户登录').click()
driver.find_element_by_id('loginname').click()
driver.find_element_by_id('loginname').send_keys(username)
driver.find_element_by_id('nloginpwd').click()
driver.find_element_by_id('nloginpwd').send_keys(password) driver.find_element_by_id('loginsubmit').click()
time.sleep(1)
driver.find_element_by_id('signIn').click()
上一篇:SQL Server2017+SSIS+Python


下一篇:button按钮