2013-03-06 135 views
1

有谁知道如何在python中安装硒?Python + Selenium Webdriver

是的,我用窗户。我的Python 2.7

所以我尝试使用此链接:https://pypi.python.org/pypi/selenium

但问题是:在我运行“PIP安装-U命令硒”?后

+0

只是将该文件夹复制到c:\ python27 \ Lib文件 – 2013-03-06 16:58:59

+0

是的,有人知道。你有更具体的问题吗?什么OS?什么版本的Python?哪个Selenium Webdriver?你遇到什么错误? – 2013-03-06 16:59:00

+1

你试过了吗? – Arran 2013-03-06 17:21:15

回答

3
pip install -U selenium 

java -jar selenium-server-standalone-2.31.0.jar 

简单的例子:

from selenium import webdriver 
from selenium.common.exceptions import NoSuchElementException 
from selenium.webdriver.common.keys import Keys 
import time 

browser = webdriver.Firefox() # Get local session of firefox 
browser.get("http://www.yahoo.com") # Load page 
assert "Yahoo!" in browser.title 
elem = browser.find_element_by_name("p") # Find the query box 
elem.send_keys("seleniumhq" + Keys.RETURN) 
time.sleep(0.2) # Let the page load, will be added to the API 
try: 
    browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]") 
except NoSuchElementException: 
    assert 0, "can't find seleniumhq" 
browser.close() 
+0

您也可以手动下载Selenium(https://pypi.python.org/pypi/selenium),然后在您的项目中添加selenium文件夹('selenium-2.31.0/py/selenium /')。这种方式更容易分发,并且不会依赖于先在其他人的机器上使用'pip':) – 2013-03-06 17:03:11

+0

直到那时我只安装了python(http://www.python.org/download/) SO :Windows – RFtests 2013-03-06 17:07:03