jonhoo / fantoccini

A high-level API for programmatically interacting with web pages through WebDriver.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

An error occurs in the IE mode of the Edge browser.

mishan88 opened this issue · comments

fantoccini is very useful library and I want to use with IE mode of the Edge browser. (I know I should not use Internet Explorer...)

Expected Behavior

  • The IE mode of the Edge browser works.

Current Behavior

  • The following code does not work well with the IE mode of the Edge browser.
use fantoccini::ClientBuilder;
use anyhow::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let mut capabiliteies = serde_json::map::Map::new();
    capabiliteies.insert("browserName".into(), "internet explorer".into());
    let options = serde_json::json!({
        "ie.edgechromium": true
    });
    capabiliteies.insert("se:ieOptions".into(), options);
    let _client = ClientBuilder::native().capabilities(capabiliteies).connect("http://localhost:9515").await?;
    Ok(())
}
  • error message
Error: webdriver did not create session: No matching capability sets found.
Unable to match capability set 0: goog:chromeOptions is an unknown extension capability for IE

Possible Solution

  • Node.js selenium-webdriver could works, and there is not goog:chromeOptions.
Capabilities {
  map_: Map(11) {
    'acceptInsecureCerts' => false,
    'browserName' => 'internet explorer',
    'browserVersion' => '11',
    'pageLoadStrategy' => 'normal',
    'platformName' => 'windows',
    'proxy' => {},
    'se:ieOptions' => {
      browserAttachTimeout: 0,
      elementScrollBehavior: 0,
      enablePersistentHover: true,
      'ie.browserCommandLineSwitches': '',
      'ie.edgechromium': true,
      'ie.edgepath': '',
      'ie.ensureCleanSession': false,
      'ie.fileUploadDialogTimeout': 3000,
      'ie.forceCreateProcessApi': false,
      ignoreProtectedModeSettings: false,
      ignoreZoomSetting: true,
      initialBrowserUrl: 'http://localhost:52298/',
      nativeEvents: true,
      requireWindowFocus: false
    },
    'setWindowRect' => true,
    'strictFileInteractability' => false,
    'timeouts' => { implicit: 0, pageLoad: 300000, script: 30000 },
    'unhandledPromptBehavior' => 'dismiss and notify'
  }
}
  • It works if I delete the following code in session.rs.
        // make chrome comply with w3c
        cap.entry("goog:chromeOptions".to_string())
            .or_insert_with(|| Json::Object(serde_json::Map::new()))
            .as_object_mut()
            .expect("goog:chromeOptions wasn't a JSON object")
            .insert("w3c".to_string(), Json::from(true));

Steps to Reproduce

  • run IEDriverServer
.\IEDriverServer.exe /port=9515 /log-level=DEBUG
  • run script
cargo run

Environment

  • cargo.toml
[dependencies]
anyhow = "1.0.70"
fantoccini = { path = "./fantoccini" }
serde_json = "1.0.96"
tokio = { version = "1.27.0", features = ["full"] }
  • OS: Windows11
  • IE Webdriver: 4.8.1

Thanks for the detailed report!

Hmm, this one is tricky, because we don't actually know in advance which browser we're going to be talking to. I wonder if the trick to pull here is to look in cap for se:ieOptions, and if present, to not run

fantoccini/src/session.rs

Lines 633 to 638 in 446a1c3

// make chrome comply with w3c
cap.entry("goog:chromeOptions".to_string())
.or_insert_with(|| Json::Object(serde_json::Map::new()))
.as_object_mut()
.expect("goog:chromeOptions wasn't a JSON object")
.insert("w3c".to_string(), Json::from(true));

Would you want to take a stab at writing up a PR? Should hopefully be pretty straightforward.

@stevepryde I'm curious on your take here too — how would you expect per-browser capabilities injected by fantoccini to work?

Thank you for your response! I'll try writing up a PR.
To tell you the truth, I tried thirtyfour InternetExplorerCapbilities at first, but this didn’t work well either.