GetDocument(Control) method is gone?

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
gisiman
Posts: 8
Joined: Sat Jan 02, 2010 6:34 pm

GetDocument(Control) method is gone?

Post by gisiman » Sat Jan 02, 2010 8:04 pm

now I am testing Ranorex 2.2(using trial version)

How can I create the instance of the WebDocument object related to the instance of the WebBrowser control in Ranorex v2.2?

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

Re: GetDocument(Control) method is gone?

Post by Support Team » Sat Jan 02, 2010 11:31 pm

All the WebDocuments of a web browser are descendants of the web browser element, so you can just search for the WebDocument relatively inside the browser control:
Form webBrowser = "pathToWebBrowserForm";
WebDocument doc = webBrowser.FindSingle("//webdocument");
// or use the FindDescendant method
doc = webBrowser.FindDescendant<WebDocument>();
See the following section in the Ranorex User Guide on how to search relatively using RanoreXPath: http://www.ranorex.com/support/user-gui ... xpath.html

Regards,
Alex
Ranorex Support Team

gisiman
Posts: 8
Joined: Sat Jan 02, 2010 6:34 pm

Re: GetDocument(Control) method is gone?

Post by gisiman » Sun Jan 03, 2010 3:23 pm

I don't understand suggested code.
what is 'pathToWebBrowserForm'?

My C# App have form1 and web browser contrl name is webbrowser1 in form1.
How can I write code in this case?
please write example code..

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

Re: GetDocument(Control) method is gone?

Post by Support Team » Sun Jan 03, 2010 5:44 pm

gisiman wrote:what is 'pathToWebBrowserForm'?
'pathToWebBrowserForm' is the RanoreXPath (see http://www.ranorex.com/support/user-gui ... xpath.html) to the web browser form, in your case this is most likely "/form[@controlname='form1']". You get the path if you use Ranorex Spy to track the form that contains your web browser control.

The WebDocument.GetDocument method available in Ranorex 1.5 is no longer needed, because in Ranorex 2.X all elements (including web elements) form a common element tree that is visible in Ranorex Spy. Every element is identified by a RanoreXPath that can be used to search for a distinct element.

If you are new to Ranorex or have only used Ranorex 1.X before, please read through the Ranorex Tutorial (http://www.ranorex.com/Documentation/Ra ... torial.pdf) and the Ranorex User Guide (http://www.ranorex.com/support/user-guide-20.html). A few more advanced topics are also covered by the Ranorex screencasts (http://www.ranorex.com/support/screencasts.html).

Note, that there are major differences in the methodology of Ranorex 1.X and Ranorex 2.X; Ranorex 2.X is rather a new product than just a new version of Ranorex, consequently Ranorex 1.X and 2.X code is in most cases not compatible!

Regards,
Alex
Ranorex Support Team

gisiman
Posts: 8
Joined: Sat Jan 02, 2010 6:34 pm

Re: GetDocument(Control) method is gone?

Post by gisiman » Mon Jan 04, 2010 2:51 am

Code: Select all

Form frmMain = "/form[@controlname='form1']";
WebDocument webDoc = frmMain.FindSingle("//webdocument");  
            
webDoc.Navigate("http://www.naver.com");
webDoc.WaitForDocumentLoaded();
1line occur error
"Ranorex.ElementNotFoundException: No element found for path '/form[@controlname='form1']' within 10s....

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

Re: GetDocument(Control) method is gone?

Post by Support Team » Mon Jan 04, 2010 9:48 am

I said that this is "most likely" the path to your form, but you should have checked using Ranorex Spy! Please read the Ranorex User Guide on how to analyze your application with Ranorex Spy:
http://www.ranorex.com/support/user-gui ... x-spy.html

Please be aware that attributes in RanoreXPath are case sensitive, please check if the control name of your form is "form1" or "Form1"! You can easily do that by tracking the form in Ranorex Spy!

Regards,
Alex
Ranorex Support Team

gisiman
Posts: 8
Joined: Sat Jan 02, 2010 6:34 pm

Re: GetDocument(Control) method is gone?

Post by gisiman » Tue Jan 05, 2010 7:54 am

u are right. 'Form1' is correct name. so I can use instance of web browser control in From1.

but Navagate method don't run.

//this Code run correctly
webBrowserControl1.Navigate("about:blank");
Form frmThis = "/form[@controlname='Form1']";
WebDocument webDoc = frmThis.FindDescendant<WebDocument>();

//Try New Page Loading..but..
webDoc.Navigate("http://www.naver.com"); //Stop Execution at this line. no response...
webDoc.WaitForDocumentLoaded();


please..help me~

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: GetDocument(Control) method is gone?

Post by Ciege » Tue Jan 05, 2010 7:08 pm

Have you tried without the WaitForDocumentLoaded?
If there is a windows dialog that happens to appear that needs end user interaction or the document object never successfully reports back that the document is loaded then the document will never get into a loaded state so you will end up in a loop of waiting that will never end.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

gisiman
Posts: 8
Joined: Sat Jan 02, 2010 6:34 pm

Re: GetDocument(Control) method is gone?

Post by gisiman » Wed Jan 06, 2010 5:42 am

Thanks Ciege.

Already I have tried it. but I got same result.

In my code, webDoc is correct instance of Web Browser control.
hum..I don't know what I do next try.. :cry:

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

Re: GetDocument(Control) method is gone?

Post by Support Team » Wed Jan 06, 2010 9:28 pm

Do you try to automate an application from the same application, i.e. automated and automating application are the same? That's usually not a problem as long as you do not use the GUI thread for automating, but a separate thread that executes the Ranorex code.

I guess you added the Ranorex automation code inside an event handler in your Windows Forms application, i.e. the code is executed on the same thread that updates the user interface of your application. That works until you invoke a Ranorex method that waits for some change in the user interface. That results in a deadlock since the GUI cannot change before the event handler method returns which is blocked by the call to the Ranorex method (in your case the WebDocument.Navigate method).

The solution to this problem is to use a separate thread that executes all the Ranorex automation code, i.e. instead of executing the code in your event handler directly, create a new thread the executes the same code:
using System.Threading;

// your event handler method
private static void MyButton_Click(EventArgs e)
{
    // next line is OK, since it is not a Ranorex method
    webBrowserControl1.Navigate("about:blank");

    Thread thread = new Thread(new ThreadStart(RunAutomation));
    thread.SetApartmentState(ApartmentState.STA);
    thread.Name = "RunAutomation";
    thread.Start();
}

// code in this method is executed on a separate thread
private static void RunAutomation()
{
    Form frmThis = "/form[@controlname='Form1']";
    WebDocument webDoc = frmThis.FindDescendant<WebDocument>();

    webDoc.Navigate("http://www.naver.com/");
    webDoc.WaitForDocumentLoaded();
}
Regards,
Alex
Ranorex Support Team