WinAppDriver fails to recognize the element visible in the Inspect.exe
I am starting the application via WinAppdriver. Creating a session and do some operations.
For one point I try to click in the desired object, which appears in the Inspect.exe, however it throws me NoSuchElementException.
I cannot understand the problem. Can it be because one of the parents of the desired object does not have a identifier such as Name or Accessibility ID ?
Any help will be appreciated.
Thanks.
Are you using Focus Watch or Cursor Watch (or another option: caret, tooltips, etc.) in the Inspect tool? I've found that using Cursor Watch shows exactly what appears in the PageSource generated by WinAppDriver, but Focus Watch can find a lot more controls than are found by WinAppDriver (which I'd love to see fixed/implemented - this is a blocker on my end).
Thank you for the response.
Actually I had cursor and focus mode on, but now when I am turning the focus off, and have only cursor on, it is still visible. I am not sure where this problem is coming from. When I am debugging all the parents are found except the needed element.
What type of app are you running (legacy Win32, UWP, WPF, WinForms)?
Can you try to see if UI Recorder picks up the element and you are able to use XPath to interact with it?
The application is WinForms based.
I will try that and report back..
@hassanuz I have tried using UIRecorder and generating Xpath, the error I am getting now is as follows:
HTTP/1.1 501 Not Implemented Content-Length: 62 Content-Type: text/plain; charset=utf-8
Unimplemented Command: xpath locator strategy is not supported
Also, I cannot find FindElementbyAbsoluteXPath option ?
Do I need to add package for it ?
Can you provide the name of the app and element that you want to interact? I can try in my environment.
I have the same issue that I cannot find FindElementbyAbsoluteXPath option. Not sure what I'm missing here.
My application is private called Empyrean Solutions, and unfortunately I cannot provide it. So there is no way it can be fixed or I can try something for it to be fixed ?
Instead of trying to use Inspect or the UIRecorder to identify the element, try saving out the PageSource right before you look for it in the code. Parse through that to find the element. Check if the information found provides a unique identifier.
@grpeacock okay, I will try that, but I want to note that the application is desktop.
For who cannot compile FindElementbyAbsoluteXPath() function,
I found that it's referred from here: link to the project, or link to the file.
I also made a portable class (C#) that is easy to copy to project as below:
public static class Utility
{
public static WindowsElement FindElementByAbsoluteXPath(this WindowsDriver<WindowsElement> desktopSession, string xPath, int nTryCount = 15)
{
WindowsElement uiTarget = null;
while (nTryCount-- > 0)
{
try
{
uiTarget = desktopSession.FindElementByXPath(xPath);
}
catch {}
if (uiTarget != null)
{
break;
}
else
{
System.Threading.Thread.Sleep(2000);
}
}
return uiTarget;
}
}
FYI I have the same problem with my WPF desktop application. Some of the elements are visible via inspect.exe but cannot be found using WinAppDriver.exe. Will comment further if our developer finds out the reason why.
I faced this issue today. MS 'Outlook' desktop application on Windows 10 (Office 16). I was able to add a new profile name, clicked OK. Next comes Setup Email Address window, with a text field for entering email ID, and a button with name 'Connect'. The email edit text box is detected by inspect, but not by driver.find_element_by_name('Email address'), not by driver.find_element_by_accessibility_id('1'), not by driver.find_element_by_class_name('RICHEDIT60W') and not even listed by driver.find_elements_by_xpath('//*'). Enter the email ID manually, then selenium could find and click the button. Python 3.8.5.
Does someone know plans regarding the fixing this bug?
I'm in the same boat here
Same boat here. I'm investigating UI automation for the product line I'm a developer for, and can't seem to get past this issue. The weird thing to me is that I can't find a pattern to what does and doesn't work. I can find dynamically loaded UserControls with XAML templates in some cases, but in one case I have a control that inherits from Button and has a template and is dynamically loaded. The button contains NO elements when I enumerate them by var allElements = elem.FindElementsByXPath(".//*"); despite Inspect seeing everything just fine, even in "Watch Cursor" only mode. I'm currently installing the SDK on the target machine to ensure that Inspect sees them there too (both dev and target machine are Windows 10 with current updates). If I find anything I'll update.
Same boat here. I'm investigating UI automation for the product line I'm a developer for, and can't seem to get past this issue. The weird thing to me is that I can't find a pattern to what does and doesn't work. I can find dynamically loaded UserControls with XAML templates in some cases, but in one case I have a control that inherits from Button and has a template and is dynamically loaded. The button contains NO elements when I enumerate them by var allElements = elem.FindElementsByXPath(".//*"); despite Inspect seeing everything just fine, even in "Watch Cursor" only mode. I'm currently installing the SDK on the target machine to ensure that Inspect sees them there too (both dev and target machine are Windows 10 with current updates). If I find anything I'll update.
Inspect sees the elements within our custom button control just fine on the target machine as well. If I enumerate all elements from the root in my test code I can see the custom button elements but they are empty despite Inspect seeing everything within them.