* 示例代码:
```python
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get('http://www.yahoo.com')
assert 'Yahoo' in browser.title
elem = browser.find_element_by_name('p') # Find the search box
elem.send_keys('seleniumhq' + Keys.RETURN)
browser.quit()
等待页面加载:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "myDynamicElement"))
)
finally:
driver.quit()
配置文档:
selenium:
chromedriver:
brew install chromedriver
brew tap homebrew/cask
brew cask install chromedriver
手动安装:
步骤二: 修改文件权限
sudo chmod u+x,o+x /usr/local/bin/chromedriver
检查是否安装成功:
chromedriver --version
pip install selenium