Selenium 3 到 4 - org.openqa.selenium.WebDriverException:到达错误页面:在 Firefox 浏览器中启动 URL 时

问题描述 投票:0回答:1

我正在将框架从 Selenium 3.0 更新到 4,但遇到了一些问题。当我在 Firefox 浏览器上启动测试时,出现以下错误。

org.openqa.selenium.WebDriverException: Reached error page: about:neterror?e=nssFailure2&u=https%3A//www.google.com
Build info: version: '4.20.0', revision: '866c76ca80'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '14.4.1', java.version: '19.0.2'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Command: [1a83efbbba91fc468162d6ee738d7de1c4ba9383, get {url=https://www.google.com}]
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 95.0, moz:accessibilityChecks: false, moz:buildID: 20211129150630, moz:debuggerAddress: localhost:9222, moz:geckodriverVersion: 0.31.0, moz:headless: false, moz:processID: 46398, moz:profile: /var/folders/yj/h3bj394n2tn..., moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platformName: mac, platformVersion: 21.6.0, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webdriver.remote.sessionid: 1a83efbbba91fc468162d6ee738...}

代码

if (browser.toLowerCase().contains("firefox")) {
    FirefoxOptions ffOptions = new FirefoxOptions();
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("webdriver.load.strategy", "unstable");
    profile.setAssumeUntrustedCertificateIssuer(false);
    profile.setPreference("browser.download.dir", "C:\\download");
    profile.setPreference("browser.download.folderList", 2);

    ffOptions.setCapability("browserName", "Firefox");
    ffOptions.setCapability("browserVersion", "95.0");
    HashMap<String, Object> bstackOptions = new HashMap<String, Object>();
    browserstackOptions.put("os", "OS X");
    browserstackOptions.put("osVersion", "Monterey");
    browserstackOptions.put("buildName", "Selenium Java Firefox Profile");
    browserstackOptions.put("sessionName", "Selenium Java Firefox Profile");
    ffOptions.setCapability("bstack:options", browserstackOptions);
    ffOptions.setProfile(profile);
    try {
        browserStackDriver = new RemoteWebDriver(new URL(gds.BROWSERSTACK_URL), ffOptions);
    } catch (Exception e) {
        logger.info("could not connect to remote driver " + testCase + " OS " + os + " Browser " + browser);
        throw (new NullPointerException(e.getMessage()));
    }
}
java selenium-webdriver selenium-firefoxdriver
1个回答
0
投票
package com.profiling;

import java.util.HashMap;
import java.util.Map;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;

public class LaunchFirefoxBrowser {
public static void main(String[] args){
    System.out.println("Inside main in Java");


    FirefoxProfile profile = new FirefoxProfile();
    FirefoxOptions ffOptions = new FirefoxOptions();
    ffOptions.setProfile(profile);

    Map<String, Object> ffOpts = new HashMap<>();
    ffOpts.put("os", "Sonoma");
    ffOpts.put("osVersion", "14.4.1");
    //ffOpts.put("moz:platformVersion", browser.split("_")[1]);

    ffOptions.setCapability("firefoxOption:options", ffOpts);
    WebDriver driver = new FirefoxDriver(ffOptions);
    driver.get("https://www.google.com/");
    driver.quit();
}


}

© www.soinside.com 2019 - 2024. All rights reserved.