{"id":13478605,"url":"https://github.com/jonhoo/fantoccini","last_synced_at":"2025-05-11T03:42:40.351Z","repository":{"id":21395681,"uuid":"92643295","full_name":"jonhoo/fantoccini","owner":"jonhoo","description":"A high-level API for programmatically interacting with web pages through WebDriver.","archived":false,"fork":false,"pushed_at":"2025-05-09T20:21:25.000Z","size":956,"stargazers_count":1815,"open_issues_count":32,"forks_count":134,"subscribers_count":19,"default_branch":"main","last_synced_at":"2025-05-11T03:42:12.830Z","etag":null,"topics":["automation","library","rust","webdriver"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonhoo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-05-28T06:08:37.000Z","updated_at":"2025-05-10T16:45:32.000Z","dependencies_parsed_at":"2024-01-14T04:35:32.765Z","dependency_job_id":"0f6537bc-a30f-4f51-93ab-15bd79a95be4","html_url":"https://github.com/jonhoo/fantoccini","commit_stats":{"total_commits":599,"total_committers":76,"mean_commits":7.881578947368421,"dds":0.4941569282136895,"last_synced_commit":"10855536d76fbf48f0493a5d297ad2f043311b75"},"previous_names":[],"tags_count":76,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonhoo%2Ffantoccini","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonhoo%2Ffantoccini/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonhoo%2Ffantoccini/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonhoo%2Ffantoccini/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonhoo","download_url":"https://codeload.github.com/jonhoo/fantoccini/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253514552,"owners_count":21920334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","library","rust","webdriver"],"created_at":"2024-07-31T16:01:59.293Z","updated_at":"2025-05-11T03:42:40.327Z","avatar_url":"https://github.com/jonhoo.png","language":"Rust","readme":"# fantoccini\n\n[![Crates.io](https://img.shields.io/crates/v/fantoccini.svg)](https://crates.io/crates/fantoccini)\n[![Documentation](https://docs.rs/fantoccini/badge.svg)](https://docs.rs/fantoccini/)\n[![codecov](https://codecov.io/gh/jonhoo/fantoccini/graph/badge.svg?token=NteBJ0F7Ok)](https://codecov.io/gh/jonhoo/fantoccini)\n\nA high-level API for programmatically interacting with web pages through WebDriver.\n\nThis crate uses the [WebDriver protocol] to drive a conforming (potentially headless) browser\nthrough relatively high-level operations such as \"click this element\", \"submit this form\", etc.\n\nMost interactions are driven by using [CSS selectors]. With most WebDriver-compatible browser\nbeing fairly recent, the more expressive levels of the CSS standard are also supported, giving\nfairly [powerful] [operators].\n\nForms are managed by first calling `Client::form`, and then using the methods on `Form` to\nmanipulate the form's fields and eventually submitting it.\n\nFor low-level access to the page, `Client::source` can be used to fetch the full page HTML\nsource code, and `Client::raw_client_for` to build a raw HTTP request for a particular URL.\n\n## Examples\n\nThese examples all assume that you have a [WebDriver compatible] process running on port 4444.\nA quick way to get one is to run [`geckodriver`] at the command line.\n\nLet's start out clicking around on Wikipedia:\n\n```rust\nuse fantoccini::{ClientBuilder, Locator};\n\n// let's set up the sequence of steps we want the browser to take\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), fantoccini::error::CmdError\u003e {\n    let c = ClientBuilder::native().connect(\"http://localhost:4444\").await.expect(\"failed to connect to WebDriver\");\n\n    // first, go to the Wikipedia page for Foobar\n    c.goto(\"https://en.wikipedia.org/wiki/Foobar\").await?;\n    let url = c.current_url().await?;\n    assert_eq!(url.as_ref(), \"https://en.wikipedia.org/wiki/Foobar\");\n\n    // click \"Foo (disambiguation)\"\n    c.find(Locator::Css(\".mw-disambig\")).await?.click().await?;\n\n    // click \"Foo Lake\"\n    c.find(Locator::LinkText(\"Foo Lake\")).await?.click().await?;\n\n    let url = c.current_url().await?;\n    assert_eq!(url.as_ref(), \"https://en.wikipedia.org/wiki/Foo_Lake\");\n\n    c.close().await\n}\n```\n\nHow did we get to the Foobar page in the first place? We did a search!\nLet's make the program do that for us instead:\n\n```rust\n// -- snip wrapper code --\n// go to the Wikipedia frontpage this time\nc.goto(\"https://www.wikipedia.org/\").await?;\n// find the search form, fill it out, and submit it\nlet f = c.form(Locator::Css(\"#search-form\")).await?;\nf.set_by_name(\"search\", \"foobar\").await?\n .submit().await?;\n\n// we should now have ended up in the right place\nlet url = c.current_url().await?;\nassert_eq!(url.as_ref(), \"https://en.wikipedia.org/wiki/Foobar\");\n\n// -- snip wrapper code --\n```\n\nWhat if we want to download a raw file? Fantoccini has you covered:\n\n```rust\n// -- snip wrapper code --\n// go back to the frontpage\nc.goto(\"https://www.wikipedia.org/\").await?;\n// find the source for the Wikipedia globe\nlet img = c.find(Locator::Css(\"img.central-featured-logo\")).await?;\nlet src = img.attr(\"src\").await?.expect(\"image should have a src\");\n// now build a raw HTTP client request (which also has all current cookies)\nlet raw = img.client().raw_client_for(http::Method::GET, \u0026src).await?;\n\n// we then read out the image bytes\nuse futures_util::TryStreamExt;\nlet pixels = raw\n    .into_body()\n    .try_fold(Vec::new(), |mut data, chunk| async move {\n        data.extend_from_slice(\u0026chunk);\n        Ok(data)\n    })\n    .await\n    .map_err(fantoccini::error::CmdError::from)?;\n// and voilà, we now have the bytes for the Wikipedia logo!\nassert!(pixels.len() \u003e 0);\nprintln!(\"Wikipedia logo is {}b\", pixels.len());\n\n// -- snip wrapper code --\n```\n\nFor more examples, take a look at the `examples/` directory.\n\n# Contributing to fantoccini\n\nThe following information applies only to developers interested in contributing\nto this project. If you simply want to use it to automate web browsers you can\nskip this section.\n\n## How to run tests\n\nThe tests assume that you have [`chromedriver`] and [`geckodriver`] already running on your system.\nYou can download them using the links above. Then run them from separate tabs in your terminal.\nThey will stay running until terminated with Ctrl+C or until the terminal session is closed.\n\nThen run `cargo test` from this project directory.\n\n[WebDriver protocol]: https://www.w3.org/TR/webdriver/\n[CSS selectors]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors\n[powerful]: https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes\n[operators]: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors\n[WebDriver compatible]: https://github.com/Fyrd/caniuse/issues/2757#issuecomment-304529217\n[`geckodriver`]: https://github.com/mozilla/geckodriver\n[`chromedriver`]: https://chromedriver.chromium.org/downloads\n","funding_links":[],"categories":["Rust","automation"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonhoo%2Ffantoccini","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonhoo%2Ffantoccini","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonhoo%2Ffantoccini/lists"}