问题
Using Selenium 3.1.0, firefox latest version 72.0, default firefox driver 2.53.1 here is my code
System.setProperty("webdriver.gecko.driver" ,"C:\\Users\\sindhusha.tummala\\Downloads\\geckodriver.exe");
driver = new FirefoxDriver();
Still i am getting the error
org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe) on port 7055;
Could any one help with this
回答1:
This error message...
org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe) on port 7055;
...implies that the GeckoDriver binary (executable) was unable to initiate/spawn a new Browsing Context i.e. Firefox Browser session as it was unable to locate the FirefoxBinary.
This issue arises when Firefox is not installed at the default location or is not installed at all.
Solution
To solve this issue:
- If Firefox is not al all installed you have to install it.
- If Firefox is not installed at the default location you need to pass the absolute path of the Firefox binary through the argument
firefox_binary
as follows: Code block:
public class A_Firefox_binary { public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe"); FirefoxOptions options = new FirefoxOptions(); options.setBinary("C:\\path\\to\\firefox.exe"); WebDriver driver = new FirefoxDriver(options); driver.get("https://stackoverflow.com"); System.out.println("Page Title is : "+driver.getTitle()); driver.quit(); } }
Additional Consideration
Ensure that:
- Upgrade JDK to recent levels JDK 8u222.
- Upgrade Selenium to current levels Version 3.141.59.
- Upgrade GeckoDriver to GeckoDriver v0.26.0 level.
- GeckoDriver is present in the desired location.
- GeckoDriver is having executable permission for non-root users.
- Upgrade Firefox version to Firefox v70.0 levels.
- Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
- (WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
- (LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.
- If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
- Take a System Reboot.
- Execute your
Test
as a non-root user. - Always invoke
driver.quit()
withintearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.
Outro
You can find a couple of relevant discussions in:
- How to open Firefox Developer Edition through Selenium
- Python 3.5 - “Geckodriver executable needs to be in PATH”
来源:https://stackoverflow.com/questions/59709978/webdriverexception-failed-to-connect-to-binary-firefoxbinaryc-program-files-m