Hi everyone I need to get the url from a process, I'have made this
var Element = AutomationElement.FromHandle(Process.MainWindowHandle);
AutomationElement edit = Elemento.FindFirst(TreeScope.Subtree,
new AndCondition(
new PropertyCondition(AutomationElement.NameProperty, "Barra de direcciones y de búsqueda ", PropertyConditionFlags.IgnoreCase),
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)));
if (edit is null)
{
return "Null";
}
return ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value;
this code works fine on my computer (Windows 11) but when I run this code on another PC it doesn't work, sometimes it crashes,it doesn't found the search bar or sometimes found another AutomationElement like the search bar from youtube, I need your help, How can I make this code work correctly on diferent computers?