【问题标题】:Python + Selenium Webdriver [closed]Python + Selenium Webdriver [关闭]
【发布时间】:2013-03-06 16:57:09
【问题描述】:

有人知道如何在 python 中安装 selenium 吗?

是的,我使用窗户。我的python是2.7

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

但问题是:我在哪里运行“pip install -U command selenium”?

【问题讨论】:

  • 复制文件夹到c:\python27\Lib
  • 是的,有人知道。你有更具体的问题吗?什么操作系统?什么版本的 Python?哪个 Selenium Webdriver?您遇到了什么错误?
  • 是的,我使用 Windows。我的 python 是 2.7 所以我尝试使用这个链接:pypi.python.org/pypi/selenium 但问题是:我在哪里运行“pip install-U command selenium”?

标签: python selenium webdriver


【解决方案1】:
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()

【讨论】:

  • 您也可以手动下载 Selenium (pypi.python.org/pypi/selenium),然后在项目中添加 selenium 文件夹 (selenium-2.31.0/py/selenium/)。这种方式更容易分发,并且不会依赖于首先在其他人的机器上使用pip :)
  • 直到那时我才安装了 python (python.org/download) 所以:Windows
猜你喜欢
  • 2018-03-09
  • 2017-07-24
  • 2015-03-02
  • 2022-10-07
  • 2015-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多