How to explicitly specify a path to Firefox for Selenium?

末鹿安然 提交于 2019-12-21 03:59:20

问题


I got Selenium IDE, followed this post, got to

python test_default_server.py

and it complains Firefox is not in my path:

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

I could change my PATH environment variable, but I'd rather pursue the local config option they are mentioning ("explicitly specify a path"). How do I do that? What does the "*firefox3c" refer to?

Selenium 1.0.1, Python 2.5, Windows XP.


回答1:


You have to use the following string when you instantiate selenium instead of just "*firefox":

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

Notice: I'm not sure that path is correct, but it should be a similar one.

Update: Where do you instantiate your browser? By the tags in the question I suppose you're a python guy:

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()



回答2:


If on C# editor, use the following string:

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

Note: use an extra back slash before Program Files and firefox.exe, since a single backslash becomes an unrecognized escape sequence.




回答3:


This helps very much. setUp("http://localhost:8080/BingDemo/BingDriver.html", "*firefox C:\Program Files (x86)\Mozilla Firefox\firefox.exe");

However, replace all occurrences of \ with \\ in *firefox C:\Program Files (x86)\Mozilla Firefox\firefox.exe

Additionally, you could point your PATH to in environmental variables to mozilla.exe




回答4:


selenium("localhost", 4444, "*firefox C:\Program Files\Mozilla Firefox\firefox.exe", "http://change-this-to-the-site-you-are-testing/")

Worked in Java.




回答5:


For Java Solution using Selenium Webdriver, you can import the below class:

import org.openqa.selenium.firefox.FirefoxBinary; 

and use the code snippet below to instantiate a new driver by explicitly specifying the path to the firefox.exe in your local system.

DesiredCapabilities browserCapabilities = DesiredCapabilities.firefox();
FirefoxBinary ffbinary = new FirefoxBinary(new File("C:\Program Files (x86)\Mozilla Firefox\firefox.exe"));
FirefoxProfile ffprofile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(ffbinary, ffprofile, browserCapabilities);

Note: You may need to replace "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" with the path that points to firefox.exe on your local machine.




回答6:


The *firefox etc are the keys for which browser to use to run the tests.

There is a long list of them at How to run Google Chrome with Selenium RC? - so you can target Firefox v2 (*firefox2), Firefox v3 (*firefox3), Google Chrome (*googlechrome) etc




回答7:


This helps very much.

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



回答8:


I found it worth useful...

Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox C:\Program Files (x86)\Mozilla Firefox\firefox.exe", "http://gmail.com");


来源:https://stackoverflow.com/questions/1344026/how-to-explicitly-specify-a-path-to-firefox-for-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!