use anyhow::Result;
use computeruse::{Desktop, Selector};
use tokio::time::{sleep, Duration};
#[tokio::main]
async fn main() -> Result<()> {
println!("🚀 Starting scroll-into-view click test");
let desktop = Desktop::new_default()?;
println!("📱 Opening Chrome browser...");
desktop.open_application("chrome")?;
sleep(Duration::from_secs(2)).await;
println!("🌐 Navigating to example page with scrollable content...");
desktop
.locator(Selector::from("role:textbox|name:Address and search bar"))
.wait(Some(Duration::from_secs(5)))
.await?
.type_text(
"https://en.wikipedia.org/wiki/Rust_(programming_language)",
true,
)?;
desktop
.locator(Selector::from("role:textbox|name:Address and search bar"))
.wait(Some(Duration::from_secs(1)))
.await?
.press_key("Return")?;
sleep(Duration::from_secs(3)).await;
println!("📜 Attempting to click on 'External links' section (likely off-screen)...");
let external_links = desktop
.locator(Selector::from("role:hyperlink|name:External links"))
.wait(Some(Duration::from_secs(5)))
.await?;
if let Ok(bounds) = external_links.bounds() {
println!("📍 Element position before action: y={}", bounds.1);
if bounds.1 > 1080.0 {
println!(" ⚠️ Element is off-screen (y > 1080)");
}
}
println!("🎯 Clicking on 'External links' (will auto-scroll if needed)...");
external_links.click()?;
sleep(Duration::from_secs(2)).await;
if let Ok(bounds) = external_links.bounds() {
println!("📍 Element position after click: y={}", bounds.1);
if bounds.1 <= 1080.0 {
println!(" ✅ Element successfully scrolled into view!");
}
}
println!(
"\n✨ Test completed! The element was automatically scrolled into view before clicking."
);
println!("📝 This demonstrates that all interaction methods now include scroll-into-view functionality.");
Ok(())
}