Closed zenitogr closed 6 months ago
version 1:
use uiautomation::UIAutomation;
use uiautomation::controls::ControlType;
use uiautomation::controls::EditControl;
use uiautomation::actions::Value;
fn main(){
let automation = UIAutomation::new().unwrap();
let matcher = automation.create_matcher().contains_name("- Google Chrome").control_type(ControlType::Pane);
let google_win=matcher.find_first().unwrap();
let adress_bar = automation.create_matcher().from(google_win.clone()).name("Address and search bar").depth(8).find_first().unwrap();
let edit_control:EditControl= adress_bar.try_into().unwrap();
let url=edit_control.get_value().unwrap();
println!("{}", url);
}
version 2: uses UICondition.
use uiautomation::UIAutomation;
use uiautomation::controls::ControlType;
use uiautomation::controls::EditControl;
use uiautomation::types::TreeScope;
use uiautomation::types::UIProperty;
use uiautomation::variants::Variant;
use uiautomation::actions::Value;
fn main(){
let automation = UIAutomation::new().unwrap();
let matcher = automation.create_matcher().contains_name("- Google Chrome").control_type(ControlType::Pane);
let google_win=matcher.find_first().unwrap();
let cond=automation.create_property_condition(UIProperty::Name, Variant::from("Address and search bar"),None).unwrap();
let adress_bar=google_win.find_first(TreeScope::Descendants, &cond).unwrap();
let edit_control:EditControl= adress_bar.try_into().unwrap();
let url=edit_control.get_value().unwrap();
println!("{}", url);
}
tested on Windows 10, Chrome 108 . Can't answer your question directly because of my bad english.
can someone give me a how to use this crate to get the browser (chrome) url?
I am trying to translate this answer https://stackoverflow.com/questions/46470737/c-sharp-uia-get-microsoft-edge-url to rust using uiautomation but fail!
how to use UICondition? in that first line in the above answer?
in the first like it compares the process title with google chrome
then it gets the first element
my code so far:
let elm1 = elm.find_first(TreeScope::from(2), UICondition::property(UIProperty::Name, Variant::from("Google Chrome"))).unwrap();