【问题标题】:Why URL not working with Selenium in FirefoxDriver?为什么 URL 在 FirefoxDriver 中不能与 Selenium 一起使用?
【发布时间】:2018-01-11 16:33:56
【问题描述】:

我有一个 Selenium、TestNG 和 maven 应用程序。

如果我运行mvn intergration-test,Firefox 浏览器会打开,但 URL 不起作用。

在控制台中也出现以下错误

Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7055

我的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.selenium</groupId>
<artifactId>Selenium</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Selenium</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <version.selenium>2.53.1</version.selenium>
    <version.testng>6.9.10</version.testng>
    <version.maven.compiler.plugin>2.3.2</version.maven.compiler.plugin>
    <version.java.source>1.8</version.java.source>
    <version.java.target>1.8</version.java.target>
</properties>

<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>${version.testng}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <!-- <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-server-standalone</artifactId> 
            <version>${version.selenium}</version> <scope>test</scope>  -->
         <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version> 
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${version.maven.compiler.plugin}</version>
            <configuration>
                <source>${version.java.source}</source>
                <target>${version.java.target}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <argLine>-Xms128m -Xmx256m -XX:PermSize=128m -XX:MaxPermSize=256m</argLine>
                <parallel>true</parallel>
                <suiteXmlFiles>
                    <suiteXmlFile>src/main/java/com/selenium/testng.xml</suiteXmlFile>
                </suiteXmlFiles>
                <!-- Skip the normal tests, we'll run them in the integration-test phase -->
                <skip>true</skip>
            </configuration>
            <executions>
                <execution>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>false</skip>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

【问题讨论】:

  • 你的火狐是什么版本的?
  • 任何时候浏览器启动但没有浏览到 URL,你应该更新你的驱动程序和浏览器,或者至少确保版本匹配。
  • @Moe:使用 Firefox 57.0.4。
  • @JeffC: 1. 如何更新我的驱动程序? 2.如何查看版本匹配。我的意思是我在哪里可以检查哪个 FF 版本适用于这个特定的 Selenium 版本?
  • 转到Selenium download site 并在“Selenium Client & WebDriver Language Bindings”下为您的语言 (Java) 获取当前 Selenium 驱动程序。然后向下滚动到“第三方驱动程序、绑定和插件”部分并获取 Mozilla GeckoDriver(FF 驱动程序)。解压缩并将它们放入您的项目中,您应该会很好。您将要启动 FF 并确保它是最新的。一旦你做了所有这些,你应该很好。如果没有,您至少会消除不匹配/旧版本问题的常见来源。

标签: selenium selenium-webdriver testng selenium-chromedriver selenium-firefoxdriver


【解决方案1】:

当浏览器版本与您的驱动程序版本不兼容时,我通常会看到这种行为,从您的 pom 中我看到您使用的是 selenium 版本 2.25,这有点旧,我认为只支持 FF 14。请确认您是使用正确版本的 Firefox。如果您在安装旧版 Firefox 时需要帮助,请参阅:

https://support.mozilla.org/en-US/kb/install-older-version-of-firefox

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-03
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    • 2021-06-14
    • 2012-10-09
    • 2020-03-18
    • 2017-11-21
    相关资源
    最近更新 更多