ElementNotFoundException

Ask general questions here.
rkarhe
Posts: 42
Joined: Thu Jul 28, 2011 5:31 am

ElementNotFoundException

Post by rkarhe » Thu Jul 28, 2011 5:49 am

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

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: ElementNotFoundException

Post by artur_gadomski » Thu Jul 28, 2011 8:36 am

Shooting in the dark: timeout? How long does the code have to find this object?

rkarhe
Posts: 42
Joined: Thu Jul 28, 2011 5:31 am

Re: ElementNotFoundException

Post by rkarhe » Thu Jul 28, 2011 11:56 am

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();

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: ElementNotFoundException

Post by artur_gadomski » Thu Jul 28, 2011 12:07 pm

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

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

Re: ElementNotFoundException

Post by Support Team » Thu Jul 28, 2011 12:08 pm

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
.
Image

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: ElementNotFoundException

Post by artur_gadomski » Thu Jul 28, 2011 12:15 pm

How nice, you can use numbers rather than Duration object. You learn new stuff everyday :D

rkarhe
Posts: 42
Joined: Thu Jul 28, 2011 5:31 am

Re: ElementNotFoundException

Post by rkarhe » Fri Jul 29, 2011 8:55 am

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);

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

Re: ElementNotFoundException

Post by Support Team » Fri Jul 29, 2011 9:02 am

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
.
Image

rkarhe
Posts: 42
Joined: Thu Jul 28, 2011 5:31 am

Re: ElementNotFoundException

Post by rkarhe » Fri Jul 29, 2011 10:45 am

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

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

Re: ElementNotFoundException

Post by Support Team » Fri Jul 29, 2011 10:51 am

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
.
Image

rkarhe
Posts: 42
Joined: Thu Jul 28, 2011 5:31 am

Re: ElementNotFoundException

Post by rkarhe » Fri Jul 29, 2011 12:07 pm

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.