Skip to content

Commit

Permalink
Save screenshots to disc in README.md (#463)
Browse files Browse the repository at this point in the history
Co-authored-by: Billy Sheppard <39789405+Billy-Sheppard@users.noreply.github.com>
  • Loading branch information
beyarkay and Billy-Sheppard committed May 9, 2024
1 parent e37a2ee commit 24e8169
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,21 @@ fn browse_wikipedia() -> Result<(), Box<dyn Error>> {
let elem = tab.wait_for_element("#firstHeading")?;
assert!(tab.get_url().ends_with("WebKit"));

// Take a screenshot of the entire browser window
let _jpeg_data = tab.capture_screenshot(
/// Take a screenshot of the entire browser window
let jpeg_data = tab.capture_screenshot(
Page::CaptureScreenshotFormatOption::Jpeg,
None,
None,
true)?;
// Save the screenshot to disc
std::fs::write("screenshot.jpeg", jpeg_data)?;

// Take a screenshot of just the WebKit-Infobox
let _png_data = tab
/// Take a screenshot of just the WebKit-Infobox
let png_data = tab
.wait_for_element("#mw-content-text > div > table.infobox.vevent")?
.capture_screenshot(Page::CaptureScreenshotFormatOption::Png)?;
// Save the screenshot to disc
std::fs::write("screenshot.png", png_data)?;

// Run JavaScript in the page
let remote_object = elem.call_js_fn(r#"
Expand Down

0 comments on commit 24e8169

Please sign in to comment.