Page 1 of 1

Unable to identiify WebDocument

Posted: Thu Aug 13, 2009 4:42 pm
by thangavel

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.

Re: Unable to identiify WebDocument

Posted: Thu Aug 13, 2009 4:51 pm
by Support Team
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

Re: Unable to identiify WebDocument

Posted: Fri Aug 14, 2009 8:14 am
by thangavel
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

Re: Unable to identiify WebDocument

Posted: Fri Aug 14, 2009 8:35 am
by Support Team
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

Re: Unable to identiify WebDocument

Posted: Fri Aug 14, 2009 10:26 am
by thangavel
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.

Re: Unable to identiify WebDocument

Posted: Thu Oct 06, 2011 2:55 pm
by Zhilll
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.

Re: Unable to identiify WebDocument

Posted: Thu Oct 06, 2011 4:03 pm
by Support Team
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