How to explicitly specify a path to Firefox for Selenium?

后端 未结 8 2328
伪装坚强ぢ
伪装坚强ぢ 2021-02-14 14:16

I got Selenium IDE, followed this post, got to

python test_default_server.py

and it complains Firefox is not in my path:

Please         


        
8条回答
  •  终归单人心
    2021-02-14 14:48

    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.

提交回复
热议问题