jonhoo / fantoccini

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to switch window in fantoccini.

grv07 opened this issue · comments

I have opened a page www.jiocloud.com and trying to automate to login.

   client.goto("https://www.jiocloud.com/").await?;
   // jio click on login.
    let ele = client
        .wait()
        .for_element(Locator::Css(r#"button.btn-login"#))
        .await?;
    ele.click().await?;

    // jio-sign in with google it will open a new window.
    let ele = client
        .wait()
        .for_element(Locator::Css(r#"button.social-btn.btn-google"#))
        .await?;
    ele.click().await?;

   // this sleep was required otherwise windows() returns only one window.
    std::thread::sleep(std::time::Duration::from_millis(1000));

    let windows = client.windows().await?; // ex: returns vec[window1, window2]

    let mut next = client.windows().await?.remove(1);
    println!("switch to >> {:?}", next); // ex: switch to >> window2
    client.switch_to_window(next);

    // still shows me previous window as active.
    println!("we are in {:?}", client.window().await?); // ex: window1

I was not waiting for an async call client.switch_to_window(next); :(
Marking as closed.