ElementNotFoundException : General Questions

ElementNotFoundException

Ask general questions here.

ElementNotFoundException

Postby rkarhe » Thu Jul 28, 2011 6: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
rkarhe
 
Posts: 33
Joined: Thu Jul 28, 2011 6:31 am

Re: ElementNotFoundException

Postby artur_gadomski » Thu Jul 28, 2011 9:36 am

Shooting in the dark: timeout? How long does the code have to find this object?
User avatar
artur_gadomski
 
Posts: 125
Joined: Mon Jul 19, 2010 7:55 am
Location: Copenhagen, Denmark

Re: ElementNotFoundException

Postby rkarhe » Thu Jul 28, 2011 12:56 pm

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();
rkarhe
 
Posts: 33
Joined: Thu Jul 28, 2011 6:31 am

Re: ElementNotFoundException

Postby artur_gadomski » Thu Jul 28, 2011 1: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-read-before-posting-t871.html
User avatar
artur_gadomski
 
Posts: 125
Joined: Mon Jul 19, 2010 7:55 am
Location: Copenhagen, Denmark

Re: ElementNotFoundException

Postby Support Team » Thu Jul 28, 2011 1: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
User avatar
Support Team
Site Admin
 
Posts: 4840
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: ElementNotFoundException

Postby artur_gadomski » Thu Jul 28, 2011 1:15 pm

How nice, you can use numbers rather than Duration object. You learn new stuff everyday :D
User avatar
artur_gadomski
 
Posts: 125
Joined: Mon Jul 19, 2010 7:55 am
Location: Copenhagen, Denmark

Re: ElementNotFoundException

Postby rkarhe » Fri Jul 29, 2011 9: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-read-before-posting-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);
rkarhe
 
Posts: 33
Joined: Thu Jul 28, 2011 6:31 am

Re: ElementNotFoundException

Postby Support Team » Fri Jul 29, 2011 10: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
User avatar
Support Team
Site Admin
 
Posts: 4840
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: ElementNotFoundException

Postby rkarhe » Fri Jul 29, 2011 11: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
rkarhe
 
Posts: 33
Joined: Thu Jul 28, 2011 6:31 am

Re: ElementNotFoundException

Postby Support Team » Fri Jul 29, 2011 11:51 am

Hi,

Please take a look to following post
unable-to-identiify-webdocument-t973.html

I think you simply forgot to set the STAThread.

Regards,
Peter
Ranorex Team
User avatar
Support Team
Site Admin
 
Posts: 4840
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: ElementNotFoundException

Postby rkarhe » Fri Jul 29, 2011 1:07 pm

Support Team wrote:Hi,

Please take a look to following post
unable-to-identiify-webdocument-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.
rkarhe
 
Posts: 33
Joined: Thu Jul 28, 2011 6:31 am


Return to General Questions

Who is online

Users browsing this forum: No registered users and 0 guests