saresend / selenium-rs

A Rust Client for the Selenium webdriver (WIP)
MIT License
175 stars 31 forks source link

[Firefox] find_element() returns Json(Error("invalid type: null ... #34

Open NiklasRosenstein opened 4 years ago

NiklasRosenstein commented 4 years ago

Hey, first time using selenium-rs, and also I'm a Rust newbie.

fn wait_for_element<'a, F, T>(f: F, interval: u32) -> Element<'a>
  where F: Fn() -> Result<Element<'a>, T>, T: std::fmt::Debug
{
  loop {
    match f() {
      Ok(el) => return el,
      Err(err) => println!("{:?}", err)
    }
    std::thread::sleep_ms(interval);
  }
}

impl ProfileConfig {

  /// Performs the login-flow with Selenium.
  #[allow(unused_must_use)]
  fn login_flow(&self, twofa: &str) {
    let mut driver = WebDriver::new(Browser::Firefox);
    driver.start_session();
    driver.navigate(&self.url.as_str());
    let el = wait_for_element(|| driver.find_element(Selector::ID, "vpnForm"), 1000);
    println!("Got element: {:?}", el)
  }

}

This leaves me with the following in the console:

Error(Status(500), "http://localhost:4444/wd/hub/session/0ac0314d-66e2-7041-b83c-5f3bcabd84d7/element")
Error(Status(500), "http://localhost:4444/wd/hub/session/0ac0314d-66e2-7041-b83c-5f3bcabd84d7/element")
Error(Status(500), "http://localhost:4444/wd/hub/session/0ac0314d-66e2-7041-b83c-5f3bcabd84d7/element")
Error(Json(Error("invalid type: null, expected a string", line: 3, column: 19)))
Error(Json(Error("invalid type: null, expected a string", line: 3, column: 19)))

The Status(500) errors is while the page has not fully loaded. Then the Json(Error(... appears once the page is loaded, so I'm assuming that the element now exists but something is going wrong in the communication with the Selenium Server?

There's nothing in the Selenium Server's stdout that seems to have a correlation with this error.

I tried using Browser::Chrome but unfortunately that leaves me with this error message instead (I believe this is due to the Chrome configuration deployed by my company disallowing loading of custom Java Script which appears to be injected by Selenium).

image

NiklasRosenstein commented 4 years ago

Actually the Chrome version works when I use a chromedriver with the correct version 😄 It still shows the popup, but it works.

Y0GAAAA commented 3 years ago

Actually the Chrome version works when I use a chromedriver with the correct version 😄 It still shows the popup, but it works.

Could you link the right versions for the Java server and the chrome WebDriver ? I can't seem to find any working combination that does not throw "Error(Json(Error("invalid type: null, expected a string", line: 3, column: 19)))"

Sorry for being late :/

nixpulvis commented 3 years ago

Same issue as #35.