如何显式地为Selenium指定Firefox的路径?

2024-10-05 14:26:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我拿到硒IDE,跟着this post,拿到

python test_default_server.py

它抱怨Firefox不在我的道路上:

Please add the directory containing ''firefox.exe'' to your PATH environment
variable, or explicitly specify a path to Firefox 3 like this:
*firefox3c:\blah\firefox.exe

我可以更改PATH环境变量,但我更愿意使用它们提到的本地配置选项(“显式指定路径”)。我该怎么做?“*firefox3c”指的是什么?

Selenium 1.0.1、Python2.5、Windows XP。


Tags: topathpytestdefaultserverfirefoxthis
3条回答

如果在C编辑器上,请使用以下字符串:

selenium = new DefaultSelenium("localhost", 4444, "*firefox C:\\Program Files\\firefox.exe", "http://www.google.com/");

注意:在程序文件和firefox.exe之前使用一个额外的反斜杠,因为一个反斜杠将成为无法识别的转义序列。

在实例化selenium而不仅仅是“*firefox”时,必须使用以下字符串:

"*firefox C:\\Program Files\\Mozilla Firefox\\firefox.exe"

注意:我不确定路径是否正确,但应该是类似的路径。

更新:你在哪里实例化你的浏览器? 根据问题中的标签,我想你是一个python人:

def setUp(self):
    self.verificationErrors = []
    self.selenium = selenium("localhost", 4444, "*firefox C:\\Program Files\\Mozilla Firefox\\firefox.exe", "http://change-this-to-the-site-you-are-testing/")
    self.selenium.start()

这很有帮助。setUp("http://localhost:8080/BingDemo/BingDriver.html", "*firefox C:\Program Files (x86)\Mozilla Firefox\firefox.exe");

但是,在*firefox中用\\替换所有出现的\

此外,还可以将环境变量的路径指向mozilla.exe

相关问题 更多 >