Page 1 of 1

FindFromPoint Problem

Posted: Thu Apr 08, 2010 10:17 am
by KeySam
Hi i asked before how to get an Xpath just via click. Now i have another problem related to it.
Almost everything seem to work fine but i cant seem to find a way how to get cells of a DataGrid(individual cells). I always only get the data grid with [language=]Host.Local.Element.FindFromPoint(Ranorex.Mouse.Position, out yourPath); [/language] .
I tried to reiterate through all childrens and some other stuff but i can seem to find rows/cells or anything.
Your help would be realy appriciated.

KeySam

Re: FindFromPoint Problem

Posted: Thu Apr 08, 2010 12:10 pm
by Support Team
Hi,

are you able to get these rows/cells with Ranorex Spy?
If you get the items with Ranorex Spy maybe your path is wrong or you do something wrong in your code.

Which technologie is used for the DataGrid?

Regards,
Peter
Ranorex Support Team

Re: FindFromPoint Problem

Posted: Thu Apr 08, 2010 12:36 pm
by KeySam
Yes i am able to get the Cells and Rows with Ranorex Spy.
The data Grid is a .net dataGrid i dont know more details i am afraid.

To the Xpath, i get the xpath by getting the element where my mouse is over at the moment, but isntead of getting the cell i get the complete dataGrid. When i try to go deeper into the grid i onlz find 2 children and nothing else. Maybe i need to convert the element first to datagrid?

MfG KeySam

Re: FindFromPoint Problem

Posted: Fri Apr 09, 2010 8:25 am
by Support Team
Ranorex Spy uses the same method to get an element from a screen position. Consequently, if the FindFromPoint method works in Spy, but does not in your code, your seems to be something wrong or missing in your Ranorex code.

My guess is that MSAA elements are not working, most likely because you call Ranorex code from a thread that does not use an Single Threaded Apartment (STA) threading model. If that's true, there should be a message in your Ranorex log file (rxlog) stating that the current thread is not set to use STA. Please, make sure that your Main method has the STAThread attribute applied to it (see Ranorex samples or newly created Ranorex project) or, if you're creating a separate thread, that the ApartmentState property of the thread is correctly set to STA.

Regards,
Alex
Ranorex Support Team

Re: FindFromPoint Problem

Posted: Fri Apr 09, 2010 9:37 am
by KeySam
Thanks for the answer though i use a Single Thread Apartment. At least i know theres something else wrong i will look into it. If you guys have any other ideas tell me.

Heres the code i am using:

Code: Select all

public static Ranorex.Core.RxPath GetXpath()
		{
						
			Ranorex.Core.RxPath myPath;
         Host.Local.Element.FindFromPoint(Ranorex.Mouse.Position, out myPath);

         MessageBox.Show(myPath.ToString());
         return myPath;
		}
KeySam

Re: FindFromPoint Problem

Posted: Fri Apr 09, 2010 2:18 pm
by KeySam
I am still stuck, i cant find anything that helps. Maybe its because i use a Keyboard Hook to read up shortcuts(that will then call the method to track?) seems unlickely but maybe thats it? If hope you guys can help me.

KeySam

Re: FindFromPoint Problem

Posted: Sun Apr 11, 2010 6:43 pm
by Support Team
Other things that could be a problem:
  • Security: the application you try to get the element from is started with administrative rights, but the process you're calling FindFromPoint from does not have these rights
  • Threading: you call FindFromPoint from the same application that you want to get an element from, but use the main window thread (e.g. when invoked by an event handler of the Form/Control). If you try to automate/get information from the application the Ranorex code is running in, always use a separate thread to run the Ranorex code!
Regards,
Alex
Ranorex Support Team

Re: FindFromPoint Problem

Posted: Mon Apr 12, 2010 12:17 pm
by KeySam
I started both applications with the same rights and its not the same process(not even application), but thanks.

Re: FindFromPoint Problem

Posted: Mon Apr 12, 2010 2:06 pm
by Support Team
Sorry, I don't have any ideas left :? I can just tell you that we use exactly that method internally in Ranorex Spy to retrieve an element from a screen location. I really don't know why that method should not be working in your application...

Did you check if the path you get from FindFromPoint is identical to the path you get when tracking the data grid with Ranorex Spy?

Regards,
Alex
Ranorex Support Team

Re: FindFromPoint Problem

Posted: Mon Apr 12, 2010 3:42 pm
by KeySam
Do you reitterate through the element afterwards or does it just give you the right thing? And also yes the Data Grid is the same element(almost 100% the same path just some extra indexes).

Re: FindFromPoint Problem

Posted: Mon Apr 12, 2010 7:24 pm
by Support Team
KeySam wrote:Do you reitterate through the element afterwards or does it just give you the right thing?
No, Ranorex Spy does not reiterate through any elements, it displays the element returned by FindFromPoint. So, if Ranorex Spy tracks the cells in the data grid immediately, the FindFromPoint method should be able to do that in your code, too.

Regards,
Alex
Ranorex Support Team