1

我正在研究硒自动化。今天我更新了我的 pom 文件以获得最新的依赖项。

<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.0.0-beta3</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>3.0.0-beta3</version>
    </dependency>

在此之后,我的测试都没有在浏览器上运行。假设 Firefox 的版本为 48,它会打开,但 webdriver 没有与浏览器交互。我得到的错误日志是:

org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary
(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7055; process output follows: 
,"syncGUID":"Ei_LbuNEIU60","location":"app-global","version":"48.0.2","type":"theme","internalName":"classic/1.0",
 "updateURL":null,"updateKey":null,"optionsURL":null,"optionsType":null,"aboutURL ":null,"icons": {"32":"icon.png","48":"icon.png"},"iconURL":null,"icon64URL":null,
"defaultLocale":{"name":"Default","description":"The default theme.","creator":"Mozilla","homepageURL":null,"contributors":["Mozilla Contributors"]},"visible":true,"active":true,"userDisabled":false,"appDisabled":false,"descriptor":"C:\\Program Files (x86)\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi","installDate":1475694945987,"updateDate":1475694945987,"applyBackgroundUpdates":1,"skinnable":true,"size":21905,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":false,"hasBinaryComponents":false,"strictCompatibility":true,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"48.0.2","maxVersion":"48.0.2"}],"targetPlatforms":[],"seen":true}

这是我今天早上在 64 位机器上将 jre 和 jdk 更改为 32 位后遇到的新错误

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
,"syncGUID":"qLUZlH20Y8gq","location":"app-global","version":"48.0.2","type":"theme","internalName":"classic/1.0","updateURL":null,"updateKey":null,"optionsURL":null,"optionsType":null,"aboutURL":null,"icons":{"32":"icon.png","48":"icon.png"},"iconURL":null,"icon64URL":null,"defaultLocale":{"name":"Default","description":"The default theme.","creator":"Mozilla","homepageURL":null,"contributors":["Mozilla Contributors"]},"visible":true,"active":true,"userDisabled":false,"appDisabled":false,"descriptor":"C:\\Program Files (x86)\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi","installDate":1475694945987,"updateDate":1475694945987,"applyBackgroundUpdates":1,"skinnable":true,"size":21905,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":false,"hasBinaryComponents":false,"strictCompatibility":true,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"48.0.2","maxVersion":"48.0.2"}],"targetPlatforms":[],"seen":true}
1475767803924   addons.xpi  DEBUG   getModTime: Recursive scan of {972ce4c6-7e08-4474-a285-3208198ce6fd}
4

1 回答 1

2

这是Selenium3Mozilla Firefox版本之间的不兼容问题。

实际上Selenium3支持可执行文件geckodriver启动Mozilla Firefox >= v47,就像其他驱动程序一样。

要解决此问题,您需要下载最新的可执行 geckodriver 并将下载的 zip 解压缩到系统中的任何位置,并将Syetem属性设置webdriver.gecko.driver为指向下载可执行 geckodriver 位置,如下所示:-

System.setProperty("webdriver.gecko.driver", "path/to/geckodriver");

WebDriver driver = new FirefoxDriver();
于 2016-10-06T02:11:17.920 回答