This is a migrated thread and some comments may be shown as answers.

Unable to locate element error when automating WPF application

11 Answers 150 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 25 Sep 2014, 12:43 PM
Hi,

We're having issues with running tests for WPF application. Tests created on one computer don't run on another computer with error "Unable to locate element. Search failed!".

When updating failing test on another computer I even get different XamlPath for the same element. Original path on first computer was:
[name 'Exact' PART_ItemsHolder] AND [XamlTag 'Exact' grid][XamlPath 'Exact' /contentpresenter[1]/grid[0]/grid[0]/textbox[1]/border[name=border]/scrollviewer[name=PART_ContentHost]/grid[0]/scrollcontentpresenter[0]/textboxview[0]]

Updated path on another computer:
[name 'Exact' PART_ItemsHolder] AND [XamlTag 'Exact' grid][XamlPath 'Exact' /contentpresenter[1]/grid[0]/grid[0]/textbox[1]/listboxchrome[name=Bd]/scrollviewer[name=PART_ContentHost]/grid[0]/scrollcontentpresenter[0]/textboxview[0]]

I marked different paths with bold. Path until bold is OK and TestStudio was able to find target element when resolving failure. However, after resolving and saving the test it fails on first computer.

What are we doing wrong?

11 Answers, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 26 Sep 2014, 10:27 AM
In case anyone will face the same issue - I found a source of it.
On different computers we had different Windows themes (I had Aero and another computer was in classic theme) - both computers run on Windows 7. After switching to classic theme everything worked. However, I have a question to Telerik support - can anyone please tell me how to bypass this issue? I'm pretty sure that on Windows 8 this test will fail. Switching back and forth Windows theme is an option but quite inconvenient. Also, I think this behavior should be explicitly noted in documentation somehow (or I just didn't search properly).
So my question will be: how do I specify path that will ignore some elements? I'd like to be able to specify in XamlPath something like XPath "//" i.e.:
[name 'Exact' PART_ItemsHolder] AND [XamlTag 'Exact' grid][XamlPath 'Exact' /contentpresenter[1]/grid[0]/grid[0]/textbox[1] // scrollviewer[name=PART_ContentHost]/grid[0]/scrollcontentpresenter[0]/textboxview[0]]
(note double // in the path).

Thanks in advance.
0
Anna
Top achievements
Rank 1
answered on 29 Sep 2014, 01:20 PM
Hello Alex, hello Telerik team!

Unfortunately, I have faced with the same problem during testing of my Silverlight app, and found the same option - to change Windows themes. Would like to join Alex and wonder if there is a better way to avoid such kind of problems?

Thank you!
0
Boyan Boev
Telerik team
answered on 30 Sep 2014, 08:31 AM
Hi,

Unfortunately we have never seen such a behavior. In order to assist you best we need to reproduce this locally so we can debug what is causing this issue.

Could you please (Alex or Anna) grant us a direct access to your application (give us the WPF application or a sample one) where we can replicate this and give you a solution.

Hope to hear from you soon.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Alex
Top achievements
Rank 1
answered on 30 Sep 2014, 06:59 PM
Hi,

Thanks for your attention to this issue. I need to contact my client about how we can provide application for Telerik and get back to you as soon as possible.
0
Alex
Top achievements
Rank 1
answered on 02 Oct 2014, 06:27 AM
Hi Boyan,

I prepared a sample application which reproduces our issue. Attached archive contains two folders: WpfApp (sample app with source code) and TestStudio (test project). Please rebuild application in Visual Studio before running test. Steps to reproduce:
1) Run test from test project while being in any Windows 7 Aero theme - it should pass
2) Switch to classic Windows theme and run test again - it should fail on second step

Please let me know if you more information from my side.

Thanks!
0
Anna
Top achievements
Rank 1
answered on 02 Oct 2014, 07:31 AM
Hi Alex,

Could you please clarify: using what theme you get your tests failed - on Aero or Classic one? My tests fail using Aero and successfully pass on Classic. And what is your case?

Thank you!
0
Alex
Top achievements
Rank 1
answered on 02 Oct 2014, 08:40 AM
Hi Anna,

On my computer things are different: test passes on Aero and fails on Classic. Quite strange that you got different results. I hope Telerik engineers will bring some light to this issue.
0
Boyan Boev
Telerik team
answered on 03 Oct 2014, 08:14 AM
Hello Alex,

Thank you for the sample application. I was able to reproduce the issue.

It seems that the issue is coming from your custom tab control (TabControlIE.cs). What is this customization doing exactly?

I have replaced your tab control with the default one TabConrol and re-record step 2. The test is now able to execute in any kinds of theme and Windows.

Please find attached the project.

Hope this helps. 

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Alex
Top achievements
Rank 1
answered on 03 Oct 2014, 12:37 PM
Hello Boyan,

Unfortunately, without TabControlEx templates for TabControl don't work and I can't see tab items. Interface in our application is based on tabs with custom templates so this is important functionality for us.
For now I found how to bypass this issue - I can force classic theme for the application. But in order to do that I need Test Studio to pass parameters to my application via command line. Could you please tell me if it's possible to do or not?
0
Ivaylo
Telerik team
answered on 08 Oct 2014, 08:01 AM
Hello Alex,

Boyan will be updating this ticket shortly.

Thank you for your patience and understanding.

Regards,
Ivaylo
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Boyan Boev
Telerik team
answered on 09 Oct 2014, 10:33 AM
Hi Alex,

Please excuse me for the delayed replay.

You can easily workaround this behavior by changing the find expression of the element. Please remove the XAML path from the find rules and use some other one (e.g. automation ID, text content e.t.c).

Let me know if this works for you.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Alex
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Anna
Top achievements
Rank 1
Boyan Boev
Telerik team
Ivaylo
Telerik team
Share this question
or