【问题标题】:Python test using selenium cannot perform simple test使用 selenium 的 Python 测试无法执行简单的测试
【发布时间】:2016-08-30 19:37:51
【问题描述】:

我正在尝试了解 Selenium,但我什至无法获得一个简单的程序来测试。 Selenium webdriver 好像没有和火狐合作,我很沮丧,所以我来 Stack Overflow 寻求帮助。

作为背景,我使用 Python,可以使用 pip 安装,并且知道命令行。 我在 windows 10、firefox 48 和 selenium webdriver 3 上使用 python 3.5.2

每当我运行 selenium 测试时,(它会打开一个 Firefox 窗口和 selenium 网站)

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.seleniumhq.org')

我总是得到一个错误:

selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: C:\ ... \AppData\Local\Temp\tmp68m5rtwt If you specified a log_file in the FirefoxBinary constructor, check it for details

它还会打开一个 firefox 窗口,并有 about:blank&utm_content=firstrun 的链接(不是有效的 url)

我在互联网上查看过类似的情况,但没有真正接近。我还尝试了许多教程,并确保我以正确的方式安装了 selenium。我注意到 Firefox 最近更新了,但我不确定这是否有任何影响。

我将不胜感激任何帮助,以及我应该做什么的说明。

【问题讨论】:

标签: python python-3.x selenium-webdriver


【解决方案1】:

Firefox 48+ 不支持webdriver.Firefox()

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True
caps["binary"] = "path/to/your/firefox"

browser = webdriver.Firefox(capabilities=caps)
browser.get('http://www.seleniumhq.org')

这就是我正在尝试的
1.下载geckodriver.https://github.com/mozilla/geckodriver/releasesv.0.10.0selenium 3(beta)
2. 添加 PATH 你的 geckodriver。
4.重命名为wires
5.重启shell
6.查看版本
$ wires --version
7. 并在代码上方运行。

【讨论】:

    猜你喜欢
    • 2016-07-22
    • 2022-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-10
    • 1970-01-01
    相关资源
    最近更新 更多