selenium python 启动Firefox

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

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

下载完后将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可以调用了:

 1 import time
 2 
 3 from selenium import webdriver
 4 import os
 5 
 6 username = "[email protected]" # 请替换成你的用户名
 7 password = "d123456789d" # 请替换成你的密码
 8 
 9 # driver = webdriver.Chrome() # 选择Chrome浏览器
10 driver = webdriver.Firefox()
11 driver.get(url='http://vip.jd.com') # 打开京东会员网站
12 time.sleep(1)
13 
14 
15 driver.find_element_by_link_text('账户登录').click()
16 driver.find_element_by_id('loginname').click()
17 driver.find_element_by_id('loginname').send_keys(username)
18 driver.find_element_by_id('nloginpwd').click()
19 driver.find_element_by_id('nloginpwd').send_keys(password)
20 
21 driver.find_element_by_id('loginsubmit').click()
22 time.sleep(1)
23 driver.find_element_by_id('signIn').click()

猜你喜欢

转载自www.cnblogs.com/jpr-ok/p/9261820.html