mattsse / chromiumoxide

Chrome Devtools Protocol rust API
Apache License 2.0
712 stars 69 forks source link

Error: ChromeMessage("Node is either not visible or not an HTMLElement") on a basic example #203

Open JohnScience opened 5 months ago

JohnScience commented 5 months ago

I copy-pasted the example provided in the README:

use futures::StreamExt;

use chromiumoxide::browser::{Browser, BrowserConfig};

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // create a `Browser` that spawns a `chromium` process running with UI (`with_head()`, headless is default)
    // and the handler that drives the websocket etc.
    let (mut browser, mut handler) =
        Browser::launch(BrowserConfig::builder().with_head().build()?).await?;

    // spawn a new task that continuously polls the handler
    let handle = async_std::task::spawn(async move {
        while let Some(h) = handler.next().await {
            if h.is_err() {
                break;
            }
        }
    });

    // create a new browser page and navigate to the url
    let page = browser.new_page("https://en.wikipedia.org").await?;

    // find the search bar type into the search field and hit `Enter`,
    // this triggers a new navigation to the search result page
    page.find_element("#searchInput")
        .await?
        .click()
        .await?
        .type_str("Rust programming language")
        .await?
        .press_key("Enter")
        .await?;

    let html = page.wait_for_navigation().await?.content().await?;

    browser.close().await?;
    handle.await;
    Ok(())
}

A browser window with wikipedia opens but crashes almost instantly. This is the console output:

C:\Users\USER\Documents\github\booking-rooms\chromiumoxide-app>cargo run
   Compiling chromiumoxide-app v0.1.0 (C:\Users\USER\Documents\github\booking-rooms\chromiumoxide-app)
warning: unused variable: `html`
  --> src\main.rs:37:9
   |
37 |     let html = page.wait_for_navigation().await?.content().await?;
   |         ^^^^ help: if this is intentional, prefix it with an underscore: `_html`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: `chromiumoxide-app` (bin "chromiumoxide-app") generated 1 warning (run `cargo fix --bin "chromiumoxide-app"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 27.60s
     Running `target\debug\chromiumoxide-app.exe`
Error: ChromeMessage("Node is either not visible or not an HTMLElement")
error: process didn't exit successfully: `target\debug\chromiumoxide-app.exe` (exit code: 1)
shulcsm commented 5 months ago

Not a bug. Wikipedia changed their markup #searchInput is no longer a valid selector.

Megaguirus commented 4 months ago

the markup for the link used in the example doesn't contain the #searchInput ID for the input element. instead use https://www.wikipedia.org/