【问题标题】:unable to launch URL in Firefox无法在 Firefox 中启动 URL
【发布时间】:2016-05-13 07:18:37
【问题描述】:

我无法在 Firefox 中启动 URL。 浏览器已成功启动,但它打开的 URL 是:“https://www.mozilla.org/en-US/firefox/43.0.4/firstrun/learnmore/”。 这个浏览器会在一段时间后自行关闭。

这可能是个人资料设置的问题,但不确定如何解决此问题。

使用的代码:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Launchingbrowsers {

    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.facebook.com/?_rdr=p");
    }
}

请帮助解决此问题

【问题讨论】:

  • 你想达到什么目的?无论 Firefox 有什么问题,驱动程序一旦认为它已经加载了 Facebook 页面就会退出。为什么不在页面加载后添加延迟,或者执行一些操作和断言?
  • 添加等待命令将无济于事,因为我试图获取的 URL 没有被加载。我的意思是不使用 driver.quit() 或 driver.close() 浏览器关闭。

标签: firefox selenium selenium-webdriver


【解决方案1】:

这可能会帮助您消除 Firefox“首次运行”页面:

Firefox webdriver opens first run page all the time

前两个答案(可能更喜欢https://stackoverflow.com/a/33939553/954442)都建议使用看起来很合理的FirefoxProfile 配置来消除问题。

【讨论】:

    【解决方案2】:

    我假设您的测试超时,因为 Firefox 无法加载配置文件,因此它可以启动浏览器但无法导航到您的网络。 您必须降级 Firefox,或升级 Selenium,或同时降级 Firefox 和 Selenium。

    【讨论】:

    • 我正在使用 selenium 和 firefox 的最新版本
    • 正如我在答案中提到的,您可能需要降级firefox。你能卸载当前的 Firefox,从这个 URL 下载 v.41。 ftp.mozilla.org/pub/firefox/releases/41.0/win32/en-US,安装并尝试再次运行测试?
    • 我试过了,但我仍然面临问题。我尝试通过 driver.get() 方法打开 facebook。但不知道为什么,Firefox 已启动但有 2 个不相关的标签。
    • 产生的错误是:由:org.openqa.selenium.WebDriverException:目标 URL www.facebook.com 格式不正确。构建信息:版本:'2.52.0',修订:'4c2593c',时间:'2016-02-11 19:03:33' 系统信息:主机:'suman',ip:'192.168.1.4',os。名称:'Windows 8.1',os.arch:'amd64',os.version:'6.3',java.version:'1.8.0_45' 驱动程序信息:driver.version:.FirefoxDriver.prototype 中的未知。 get(file:///C:/Users/SumanV/AppData/Local/Temp/anonymous7235374065244074506webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:10589) (1/2)
    • (2/2)at .DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/SumanV/AppData/Local/Temp/anonymous7235374065244074506webdriver-profile/extensions /fxdriver@googlecode.com/components/command-processor.js:12614) 在 .DelayedCommand.prototype.executeInternal_(file:///C:/Users/SumanV/AppData/Local/Temp/anonymous7235374065244074506webdriver-profile /extensions/fxdriver@googlecode.com/components/command-processor.js:12619) 在 .DelayedCommand.prototype.execute/
    【解决方案3】:

    有两种可能的解决方案。

    1. 您需要禁用 Firefox 的第一个运行页面才能使其正常工作。这可以通过设置首选项来实现

      FirefoxProfile 教授 = 新的 FirefoxProfile(); prof.SetPreference("browser.startup.homepage_override.mstone", "ignore"); prof.setPreference("startup.homepage_welcome_url.additional", "about:blank"); driver = new FirefoxDriver(prof);

    你不会遇到这个问题:)

    1. 如果第 1 点中的解决方案没有帮助,则升级 Selenium WebDriver 将解决问题。

    希望这会有所帮助:)

    【讨论】:

      【解决方案4】:

      我认为这是因为新问题出现在 Mozilla firefox 的最新更新中。

      这也发生在我身上。

      要克服这个问题,您需要将 Preference 设置为 xpinstall.signatures.required", false 到 firefox 配置文件,然后将其传递给驱动程序对象

      firefoxProfile.setPreference("xpinstall.signatures.required", false);
      

      下面的代码对我来说很好。

      static WebDriver driver=null;
      public static void main(String[] args) {
          final FirefoxProfile firefoxProfile = new FirefoxProfile();
          firefoxProfile.setPreference("xpinstall.signatures.required", false);
          driver = new FirefoxDriver(firefoxProfile);
          driver.get("https://www.google.de/");
      

      希望对你有帮助:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-02-25
        • 2020-08-05
        • 1970-01-01
        • 2021-12-18
        • 1970-01-01
        • 2018-09-05
        • 2019-09-21
        • 2017-06-23
        相关资源
        最近更新 更多