使用Selenium调用Firefox时无法连接端口7055问题求助
解决Firefox启动后无法跳转URL的NotConnectedException错误
问题现象
- Firefox可正常启动,但无法加载目标URL
- Eclipse控制台抛出
org.openqa.selenium.firefox.NotConnectedException,提示无法在45000ms内连接127.0.0.1的7055端口 - Firefox控制台输出
console.error: JsonSchemaValidator.jsm
解决方案
一、匹配版本兼容性
Selenium 4.10.0要求geckodriver最低版本为v0.33.0,当前使用的v0.32.0版本过低:
- 升级geckodriver至v0.33.0及以上,选择与Firefox 102.9.0esr(32位)对应的32位版本,避免位数不匹配导致通信失败
二、显式配置FirefoxOptions参数
修改脚本,添加端口指定和性能优化配置,强制稳定通信:
package testCases; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; public class Authentication { public static void main(String[] args) { System.setProperty("webdriver.gecko.driver","C:/usine-dev/workdir/workspace/test-bleu-horizon/src/test/resources/drivers/geckodriver.exe" ); FirefoxOptions options = new FirefoxOptions(); // 指定固定通信端口,避免自动端口冲突 options.addArguments("--marionette-port=7055"); // 禁用非必要扩展和远程连接,降低启动负载 options.addArguments("--no-remote"); options.addArguments("--disable-extensions"); WebDriver driver = new FirefoxDriver(options); driver.get("https://github.com/"); } }
三、检查端口占用情况
- 打开命令提示符,执行
netstat -ano | findstr :7055,确认7055端口是否被其他进程占用 - 若端口被占用,在任务管理器中结束对应PID的进程,或修改脚本中的端口号为未被占用的数值
四、调整Firefox内部配置
- 打开Firefox,在地址栏输入
about:config并确认风险提示 - 搜索
marionette.enabled,确保值为true - 搜索
marionette.port,设置为7055或自定义的未占用端口,重启Firefox后再运行脚本
五、修复路径与权限问题
- 确保geckodriver.exe的路径无中文、空格或特殊字符,避免解析错误
- 以管理员身份运行Eclipse,防止权限不足导致端口绑定失败
内容的提问来源于stack exchange,提问作者Khaoula ba
相关产品推荐
相关产品推荐

