import os from selenium import webdriver chromedriver = "C:Program Files (x86)GoogleChromeApplicationchromedriver.exe" os.environ["webdriver.chrome.driver"] = chromedriver driver = webdriver.Chrome(chromedriver) driver.get("http://www.baidu.com") driver.find_element_by_id("kw").send_keys("Selenium2") driver.find_element_by_id("su").click()
import os
from selenium import webdriver
chromedriver = "C:Program Files (x86)GoogleChromeApplicationchromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get("http://www.baidu.com")
driver.find_element_by_id("kw").send_keys("Selenium2")
driver.find_element_by_id("su").click()
selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location,
no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
指定Firefox浏览器程序路径
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('path')
driver = webdriver.Firefox(firefox_binary=binary)
driver.get("http://www.baidu.com")
driver.find_element_by_id("kw").send_keys("Selenium2")
driver.find_element_by_id("su").click()
浏览器记录密码,加载配置免登陆:
1.Firefox
profileDir = r'C:UsersAdministratorAppDataRoamingMozillaFirefoxProfileshkehfoij.default'
profile = webdriver.FirefoxProfile(profileDir)
driver = webdriver.Firefox(profile)
2.Chrome
option = webdriver.ChromeOptions()
option.add_argument('--usr-data-dir=C:UsersAdministratorAppDataLocalGoogleChromeUser Data')
driver = webdriver.Chrome(chrome_options=option)
谷歌驱动下载地址:
http://chromedriver.storage.googleapis.com/index.html
对应版本:
v2.21 v46-50
v2.22 v49-52
v2.23 v51-53
v2.24 v52-57
v2.25 v53-55
v2.26 v53-55
v2.27 v54-56
v2.28 v55-57
v2.29 v56-58