Test not finding highlightable elements

Ask general questions here.
djpflug23
Posts: 17
Joined: Fri Apr 15, 2011 9:13 pm

Test not finding highlightable elements

Post by djpflug23 » Wed Jan 11, 2012 3:42 pm

I have a project project where I am trying to select buttons and/or cells from a table (a Windows calendar). However, this table is difficult to place in the repository, as it disappears if you click anywhere outside of the calendar. This means that I can't use the spy to capture all the elements the way I normally would. I did find a way to capture the individual elements by doing the instant tracking, and then copying and pasting the path into a new item in the repository. When I try to highlight these elements from the repository, Ranorex almost immediately finds the cell/button that I am looking for. However, when I use one of these in my project (using a Host.Local.TryFindSingle or even a simple click), Ranorex fails to find the element. Any idea why this would be? Thanks for any help!

djpflug23
Posts: 17
Joined: Fri Apr 15, 2011 9:13 pm

Re: Test not finding highlightable elements

Post by djpflug23 » Wed Jan 11, 2012 6:42 pm

Here is a snapshot of one of the cells (a day in the calendar). Unfortunately, since the calendar disappears whenever I click outside of it, everything seems to be invalid, but I thought it might give some information at least. Thanks.
Attachments
calendar_Cell_Snapshot.rxsnp
(378.53 KiB) Downloaded 129 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Test not finding highlightable elements

Post by Support Team » Thu Jan 12, 2012 10:44 am

Hi,

I assume that you want to use this element in your code.
Please use the repository item in your code instead of using Host.Local.TryFindSingle.
To do this, open your code file, and next open the repository file (rxrep). Use drag and drop to get a variable for the element to your code. (Take it from repository, drag it to the tab of your code file, wait a second - your code file will be displayed and drop it to to the line where you want to use the repository item.

Regards,
Martin
Ranorex Support Team
.
Image

djpflug23
Posts: 17
Joined: Fri Apr 15, 2011 9:13 pm

Re: Test not finding highlightable elements

Post by djpflug23 » Thu Jan 12, 2012 3:13 pm

I can do it that way, and it does work, but I'm trying to create a method in one of our common dll's and, as far as I know, these are unable to have a repository of their own (is that correct?) Therefore, I'm unable to do that, I have to pass in the path as a string, and then use the TryFindSingle to get the repository item in order to click it. Sorry, I should have mentioned that before... Here is an example of the code:
string dayPath = CalendarPath + "/table/row[@accessiblerole='Row']/cell[@accessiblename='‎" + day + "']";
if(monthButton.Substring(0,3) == month)
{
SelectDay(dayPath);
}

public static void SelectDay(string dayPath)
{
Ranorex.Cell cell = null;
if(Host.Local.TryFindSingle(dayPath,2500,out cell))
{
cell.Click();
}
else
{
Report.Failure("Something's wrong; couldn't find correct day on the calendar");
return;
}
}
In this code, the variable CalendarPath is a parameter that is passed in, which is a string of the rxPath of the calendar, and the variable day is the date number (15 for example). When appended to each other, this path is exactly the same as the path that I used instant tracking to find, and also the path that I tried in a separate test using the repository item, which did work. But, as I stated, since we're trying to do this in a dll, there is no repository in this case, so we can't use the repository item in this specific case. Is there any way to fix it? Thanks.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Test not finding highlightable elements

Post by Support Team » Thu Jan 12, 2012 4:07 pm

Hi,
as far as I know, these are unable to have a repository of their own (is that correct?)
If you just created the dll out of a normal Ranorex project which contains a repository you can also access this repo in that project which referenced the specific dll, but just via User Code not in the action table of the recording files.
So if you have a repository with the specific item you can for instance perform a click on that element, you even can set the repository variables:
TheReferencedDll.TheRepository repoDll = TheReferencedDll.TheRepository.Instance;
      repoDll.YourRepoVariable= "View";
      repoDll.FormCalculator.MenuItemView.Click();
Is there any way to fix it?
You can as mentioned use the repository via code, or you have to find the specific element with one of our find methods.
Can you send us the whole error message?
The code looks quite okay, but it could be that the search timeout is too small, try to use 50000, for test purposes, instead of the 2500ms.

Regards,
Markus
Ranorex Support Team
.
Image

djpflug23
Posts: 17
Joined: Fri Apr 15, 2011 9:13 pm

Re: Test not finding highlightable elements

Post by djpflug23 » Thu Jan 12, 2012 5:00 pm

Thanks for the quick reply.
If you just created the dll out of a normal Ranorex project which contains a repository
I don't think this is how we did this. We created the dll as it's own, very large project. This is a large common dll that houses all of our common methods that all of our projects then reference and share.
Can you send us the whole error message?
I'm not getting any error message other than the report that I'm generating myself. Since I'm using a TryFindSingle within an if statement, if it's not found it just goes to the else clause and prints the report that I wrote. Therefore, the output is simply "Something's wrong; couldn't find correct day on the calendar". Would it be helpful if I gave a larger portion of my test code to look at?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Test not finding highlightable elements

Post by Support Team » Fri Jan 13, 2012 7:51 am

Hi,

As Markus mentioned before, please try to use a larger timeout, e.g. 5000ms.
Also print out the dayPath in the error message within the else statement and evaluate this path with Ranorex Spy after your test case crashes.
Give us feedback on this.

Regards,
Martin
Ranorex Support Team
.
Image

djpflug23
Posts: 17
Joined: Fri Apr 15, 2011 9:13 pm

Re: Test not finding highlightable elements

Post by djpflug23 » Tue Jan 17, 2012 3:27 pm

Thanks for the replies.
please try to use a larger timeout, e.g. 5000ms.
This doesn't help. I can put any timeout in and it still doesn't find the item. It just acts like the item doesn't exist.
print out the dayPath in the error message within the else statement and evaluate this path with Ranorex Spy
This is actually one of the first things that I tried when I was having trouble with the project. The paths are exactly the same! I'm really out of ideas. Thanks for any tips!

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Test not finding highlightable elements

Post by Support Team » Tue Jan 17, 2012 4:29 pm

You are welcome!

Can you please send us a snapshot of the control when it is not invalid (use <SCROLL> button), this link shows you how you can handle this?
You can also try to search just for a smaller part of the full RxPath, maybe this helps you to determine which part of your RxPath triggers that problem.
Please also send us a Ranorex Snapshot file of the component during runtime, this link shows you how you can create such a snapshot during runtime?

Regards,
Markus
Ranorex Support Team
.
Image

djpflug23
Posts: 17
Joined: Fri Apr 15, 2011 9:13 pm

Re: Test not finding highlightable elements

Post by djpflug23 » Tue Jan 17, 2012 6:59 pm

Thanks for those instructions. I've included both of the requested snapshots. The thing that I don't understand is that the create snapshot at runtime project WAS able to find the cell in the calendar, but my project was NOT able to find it, and they were using the exact same path. What's going on? Would it be helpful if I sent you my code? Thanks for all the help!
Attachments
runtimeSnapshot.rxsnp
Snapshot of the element taken during the test
(644.71 KiB) Downloaded 166 times
calendar_Snapshot.rxsnp
Snapshot of the calendar
(457.26 KiB) Downloaded 133 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Test not finding highlightable elements

Post by Support Team » Thu Jan 19, 2012 3:20 pm

Hi,

You're welcome!
What's going on?
This is a really strange behavior.
Please create a new solution and just execute the following code:
Cell cell;     
Host.Local.TryFindSingle("/form/element/container/table/row[@accessiblerole='Row' and @accessibledescription='Week 4']/cell[@accessiblename='‎15']", 30000, out cell);
cell.Click();
but ensure that the specific cell is visible and in the foreground.
Please also install the new 3.2 version.
Does it works as expected?

Regards,
Markus
Ranorex Support Team
.
Image

djpflug23
Posts: 17
Joined: Fri Apr 15, 2011 9:13 pm

Re: Test not finding highlightable elements

Post by djpflug23 » Thu Jan 19, 2012 8:25 pm

Using that bit of code did work. So is it how I'm building the paths in my code? Could that be what is causing the issues? Since it is a common method that will be used by many different people in different situations, I didn't want to hard-code the path in. Can I send my code to you to see if I messed it up somewhere? Thank you

djpflug23
Posts: 17
Joined: Fri Apr 15, 2011 9:13 pm

Re: Test not finding highlightable elements

Post by djpflug23 » Thu Jan 19, 2012 10:38 pm

After a lot of trial and error, I finally got it working! It seems that there were some invisible spaces or something in the paths that I was missing when I was constructing the paths. So when copying and pasting the path, it would work fine, but if I tried to type it in manually/modify them at all, I would miss those characters and the path wouldn't work. Here's an example:
string monthPath = "/form/element/container/table/row["+monthRow+"]/cell[@accessiblename='‎"+month+"']";
Right in front of the double quote at the beginning of the month variable, there is an invisible character. I was missing those before. Thanks for your patience and helping me figure this out.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Test not finding highlightable elements

Post by Support Team » Fri Jan 20, 2012 2:20 pm

Hi,

Glad to know that it is working now.
Would it is possible to send us the file (whole recording) which contains the not working/incorrect RxPath, maybe we can determine what triggers the problem?
You can also send it to [email protected]

Thanks in advance!

Regards,
Markus
Ranorex Support Team
.
Image

djpflug23
Posts: 17
Joined: Fri Apr 15, 2011 9:13 pm

Re: Test not finding highlightable elements

Post by djpflug23 » Fri Jan 20, 2012 3:37 pm

Just sent the code to the address provided. I hope it's helpful!