Unable to identiify WebDocument

Ranorex Studio, Spy, Recorder, and Driver.
thangavel
Posts: 50
Joined: Tue Jun 09, 2009 6:48 am
Contact:

Unable to identiify WebDocument

Post by thangavel » Thu Aug 13, 2009 4:42 pm

Code: Select all

//c# code
webDocument = "*//dom[@pageurl='http://csiboardstage/Pages/CommitmentManager.aspx']";
webDocument.Browser.Activate(); 

webDocument = "*//dom[@pageurl='http://www.Google.com']";
webDocument.Browser.Activate();
the above same code is not working from Visual studio. (Ranorex studio is giving error some times for the same code. Ranorex is identifying WebDocument only if the web browser is activated). I'm getting the following error when i'm running from visual studio 2008 & 2005.

Ranorex.ElementNotFoundException was unhandled
Message="No element found for path '*//dom[@pageurl='http://www.google.co.in/']' within 5000ms."
Source="Ranorex.Core"
StackTrace:
at Ranorex.Core.Element.FindSingle(RxPath path, Duration timeout)
at Ranorex.Core.Element.op_Implicit(String path)
at Ranorex.WebDocument.op_Implicit(String path)
at SpotLight_CsiBoard.Commitment_Manager.Commnt_Manager() in E:\Thangavel Sundaram\SpotLight\SpotLight_CsiBoard\CommitmentManager.cs:line 39
at SpotLight_CsiBoard.Program.Main(String[] args) in E:\Thangavel Sundaram\SpotLight\SpotLight_CsiBoard\Program.cs:line 13
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:


Note:
The same code was running fine without any issue when i'm using Ranorex 2.1.2.
Recently i have installed Ranorex 2.1.3. Then only i'm facing this problem.
You do not have the required permissions to view the files attached to this post.
Regards,
Thangavel.S

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Unable to identiify WebDocument

Post by Support Team » Thu Aug 13, 2009 4:51 pm

I think that your RxPaths are wrong, dom objects are usually top-level elements in Ranorex. "*//dom" means that you are not searching the top-level elements, but all elements that are descendants of top-level elements. I think you meant "/dom" which searches for a dom element in the top-level elements.

Regards,
Alex
Ranorex Support Team

thangavel
Posts: 50
Joined: Tue Jun 09, 2009 6:48 am
Contact:

Re: Unable to identiify WebDocument

Post by thangavel » Fri Aug 14, 2009 8:14 am

Hi,

Thanks for your clarification. I tried with the following code. Its working fine.

Code: Select all

	webDocument = "/dom[@pageurl='http://www.google.co.in/']";
	webDocument.Browser.Activate();
but i'm facing some other problem.
These are the steps I followed
Create Windows Application project - Visual Studio 2008 (With ranorex references):
1. Activate the expected browser
2. run the Script 5 times - Passed
3. Activate some other application
4. run the Script 5 times - Passed

Create Console Application project - Visual Studio 2008 (With ranorex references):
1. Activate the expected browser
2. run the Script 5 times - Failed
3. Activate some other application
4. run the Script 5 times - Failed
5. Refer Screenshot ()

the above code is working for windows application. But not for Console application. Please clarify me.
Note:
For the existing code

Code: Select all

webDocument = "*//dom[@pageurl='http://www.google.co.in/']";
	webDocument.Browser.Activate();
it was working for some time. Why? If the rxPath is wrong then it should not be identified at all time no? Kindly clarify me. Please refer the attached document.
Console_VS2008.JPG
You do not have the required permissions to view the files attached to this post.
Regards,
Thangavel.S

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Unable to identiify WebDocument

Post by Support Team » Fri Aug 14, 2009 8:35 am

For your Console Application please make sure that all threads have STA apartment state. Obviously, you forgot to place the STAThread attribute on you Main method, and set the apartment state for all threads you start. Otherwise, web elements can't be accessed (you should have a warning message in your log file)!

The path "*//dom[@pageurl='http://www.google.co.in/']" can work, too, but is much slower. In Ranorex dom elements are in the top-level as well as children of the corresponding browser form; i.e. they appear at two places in the element tree. So your RxPath would work with a long search timeout. That's why, given a short search timeout, it works only when the browser is active and is therefore on the top of the element list, consequently being searched as one of the first elements.

Regards,
Alex
Ranorex Support Team

thangavel
Posts: 50
Joined: Tue Jun 09, 2009 6:48 am
Contact:

Re: Unable to identiify WebDocument

Post by thangavel » Fri Aug 14, 2009 10:26 am

Hi Alex,

I understood now. I used [STAThread] attribute on my main() method for my console application. It is working now. Thank you very much for your clear explaination.
Regards,
Thangavel.S

Zhilll
Posts: 13
Joined: Thu Oct 06, 2011 2:48 pm

Re: Unable to identiify WebDocument

Post by Zhilll » Thu Oct 06, 2011 2:55 pm

I am having the same problem trying to use the WebDocument object. It doesn't seem to work unless I already have the browser opened to the web page. I even tried to use the WebDocument provided in the example, and I kept encountering the error: "Ranorex.ElementNotFoundException: No element found for path '/dom[@caption='Ranorex Test Page'] within 10s.

I am coding in a console app. Here is the code causing the error (am using Ranorex 3.1) :

Code: Select all

[STAThread]
		public static int Main(string[] args)
		{	
			WebDocument webDocument = "/dom[@caption='Ranorex Test Page']";
			webDocument.Navigate("http://www.ranorex.com/web-testing-examples");
			webDocument.WaitForDocumentLoaded();
Since I am following the example provided with Ranorex (after having no luck using WebDocument for my own app), I think there might be a bug with Ranorex, or there is a step missing from the user documentation.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Unable to identiify WebDocument

Post by Support Team » Thu Oct 06, 2011 4:03 pm

Hi,

Are you sure that you have opened the right web page?
Do you have checked with Spy if your path "/dom[@caption='Ranorex Test Page']" is correct?

Regards,
Markus
Ranorex Support Team