Page 1 of 1

ElementNotFoundException

Posted: Thu Jul 28, 2011 5:49 am
by rkarhe
Experts I am trying to identify object through my c# script but it is giving me 'ElementNotFoundException', the same object I can identify using spy. I am using Ranorex3.0.4. The same script was working on earlier version. I am stuck due to this, any suggestion what could be the problem.

Following is the RanorexXPath "TAB = ".//a[@innertext='SomeTextHere']";"

Rocky

Re: ElementNotFoundException

Posted: Thu Jul 28, 2011 8:36 am
by artur_gadomski
Shooting in the dark: timeout? How long does the code have to find this object?

Re: ElementNotFoundException

Posted: Thu Jul 28, 2011 11:56 am
by rkarhe
Thanks for your reply...

I have not set any timeout, its's Default timeout. How to set and how much timeout should i give.

ex

Ranorex.Core.Element admin1 = (Ranorex.Core.Element)mainPage.FindSingle(".//a[@innertext='SomeTextHere']");
admin1.Focus();

Re: ElementNotFoundException

Posted: Thu Jul 28, 2011 12:07 pm
by artur_gadomski
Find methods come in a version with a timeout duration. In your case it would be something like:
Ranorex.Core.Element admin1 = (Ranorex.Core.Element)mainPage.FindSingle(".//a[@innertext='SomeTextHere']", new Duration( 1 * 60 * 1000);
admin1.Focus();
for 1 minute timeout. (1 stands for minutes, 60 for seconds, and 1000 is just 1 second in miliseconds).
Try with different timeouts.I would guess if it doesn't find it in 5 minutes there is something wrong. Then save youself some time and make a shapshot of your application:
http://www.ranorex.com/forum/please-rea ... -t871.html

Re: ElementNotFoundException

Posted: Thu Jul 28, 2011 12:08 pm
by Support Team
Hi,
rkarhe wrote:I have not set any timeout, its's Default timeout. How to set and how much timeout should i give.
ex
Ranorex.Core.Element admin1 = (Ranorex.Core.Element)mainPage.FindSingle(".//a[@innertext='SomeTextHere']");
admin1.Focus();
To set the timeout of the elements you can take a look to following link if you use a repository
http://www.ranorex.com/support/user-gui ... eouts.html

If you use code, as in your case use following. you have to set the timeout in milliseconds.
Ranorex.Core.Element admin1 = (Ranorex.Core.Element)mainPage.FindSingle(".//a[@innertext='SomeTextHere']", 60000);
admin1.Focus();
FindSingle() method:
http://www.ranorex.com/Documentation/Ra ... ngle_1.htm

Regards,
Peter
Ranorex Team

Re: ElementNotFoundException

Posted: Thu Jul 28, 2011 12:15 pm
by artur_gadomski
How nice, you can use numbers rather than Duration object. You learn new stuff everyday :D

Re: ElementNotFoundException

Posted: Fri Jul 29, 2011 8:55 am
by rkarhe
artur_gadomski wrote:Find methods come in a version with a timeout duration. In your case it would be something like:
Ranorex.Core.Element admin1 = (Ranorex.Core.Element)mainPage.FindSingle(".//a[@innertext='SomeTextHere']", new Duration( 1 * 60 * 1000);
admin1.Focus();
for 1 minute timeout. (1 stands for minutes, 60 for seconds, and 1000 is just 1 second in miliseconds).
Try with different timeouts.I would guess if it doesn't find it in 5 minutes there is something wrong. Then save youself some time and make a shapshot of your application:
http://www.ranorex.com/forum/please-rea ... -t871.html
Thanks for mail. Tried with different timeout but still same problem. I am sure there is nothing wrong with xPath I am using as the same was working earlier.

Ranorex.Core.Element administratn = (Ranorex.Core.Element)ecmMainPage.FindSingle(".//a[@innertext='SomeTextHere']", new Duration( 5 * 60 * 1000));
administratn.Focus();
Cursor.Position = new Point(administratn.ScreenLocation.X, administratn.ScreenLocation.Y);

Re: ElementNotFoundException

Posted: Fri Jul 29, 2011 9:02 am
by Support Team
rkarhe wrote: I am sure there is nothing wrong with xPath I am using as the same was working earlier.
The RanoreXPath looks OK, that's why the only thing we could imagine being a problem is the timeout, since the path will go through all(!) elements on the "mainPage".

What is the exact error message you get?
Are there any warnings in the Ranorex Log File?
On the same machine, does Ranorex Spy find the RanoreXPath?
Could you make a brand new project with Ranorex Studio and just try to search for that one RanoreXPath?

Regards,
Alex
Ranorex Team

Re: ElementNotFoundException

Posted: Fri Jul 29, 2011 10:45 am
by rkarhe
Please see my answers below.
Support Team wrote:
rkarhe wrote: I am sure there is nothing wrong with xPath I am using as the same was working earlier.
The RanoreXPath looks OK, that's why the only thing we could imagine being a problem is the timeout, since the path will go through all(!) elements on the "mainPage".

What is the exact error message you get?
>>>{"No element found for path './/a[@innertext='Administration']' within 6m."}

Are there any warnings in the Ranorex Log File?
>>>One warning says
"The apartment state of the current thread is not set to STA. Please make sure that all threads accessing Ranorex methods have their apartment state set to STA."

On the same machine, does Ranorex Spy find the RanoreXPath?
>>> Yes, on same machine Ranorex Spy find the RanoreXPath.

Could you make a brand new project with Ranorex Studio and just try to search for that one RanoreXPath?
>>> Done, same problem here.

Regards,
Alex
Ranorex Team

Re: ElementNotFoundException

Posted: Fri Jul 29, 2011 10:51 am
by Support Team
Hi,

Please take a look to following post
http://www.ranorex.com/forum/unable-to- ... -t973.html

I think you simply forgot to set the STAThread.

Regards,
Peter
Ranorex Team

Re: ElementNotFoundException

Posted: Fri Jul 29, 2011 12:07 pm
by rkarhe
Support Team wrote:Hi,

Please take a look to following post
http://www.ranorex.com/forum/unable-to- ... -t973.html

I think you simply forgot to set the STAThread.

Regards,
Peter
Ranorex Team
Thnks, I am running my tests through nunit, added STAThred at the start of method and this is working fine now. Thank you very much.