Closed codoid-repos closed 2 years ago
The UIMatcher
supports to to define your custom filter:
UIMatcherFilter
traits.UIMatcher.filter()
.UIMatcherFilter
s with AndFilter
& OrFilter
.Samples:
struct FrameworkIdFilter(String);
impl MatcherFilter for FrameworkIdFilter {
fn judge(&self, element: &crate::UIElement) -> crate::Result<bool> {
let id = element.get_framework_id()?;
Ok(id == self.0)
}
}
#[test]
fn test_custom_search() {
let automation = UIAutomation::new().unwrap();
let matcher = automation.create_matcher().timeout(0).filter(Box::new(FrameworkIdFilter("Win32".into()))).depth(2);
let element = matcher.find_first();
assert!(element.is_ok());
println!("{}", element.unwrap());
}
Unfortunately, it's not a good idea to search element by Automation ID. I cannot get the Automation ID value correctly in my environment(windows 11). This property is not mandatory. AutomationId is not guaranteed to be stable across different releases or builds of an application. You can get more infomation from msdn: https://docs.microsoft.com/en-us/windows/win32/winauto/uiauto-automation-element-propids
Thank you @leexgone It works.
How to find an element using Automation ID property?
Now we can use Name, Class Name, and Control Type properties to find elements.