WaitForDocumentLoaded function???

Class library usage, coding and language questions.
ngrishakin
Posts: 42
Joined: Fri Oct 04, 2013 9:47 pm

WaitForDocumentLoaded function???

Post by ngrishakin » Wed May 17, 2017 7:36 pm

I'm trying to use WaitForDocumentLoaded(Duration) to make sure my page is totally loaded before I start doing any manipulations. Here is my simple code:

Code: Select all

           public WebDocument webDocument;
           Global.WaitTime = 60000;
           System.Diagnostics.Process.Start("iexplore.exe", "https://test.com");
           webDocument = "/dom[@domain='test.com']";
           webDocument.WaitForDocumentLoaded(Global.WaitTime);
The problem is "webDocument = "/dom[@domain='test.com']";" assignment. It waits for 10 sec before throwing exception. So if page takes longer to load it fails.
Can someone suggest better solution?
Thanks a lot,
Nik

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

Re: WaitForDocumentLoaded function???

Post by Support Team » Thu May 18, 2017 4:35 am

Hello ngrishakin,

Thanks to the vast Ranorex API and the supporting .NET Framework, you can achieve this in several different ways.I advise using more of the Ranorex API - Here is how I would achieve this:

Code: Select all

int WaitTime = 60000;
Host.Current.OpenBrowser("https://test.com", "ie");
WebDocument webDocument = Host.Current.FindSingle("/dom[@domain='test.com']", WaitTime)
WaitForDocumentLoaded(Duration) is not required when using standard Ranorex browser methods (in most cases). In situations where you need this method, I recommend targeting an element already defined in your Ranorex Repository. If you are not using a repository, I highly recommend you start for many more reasons than just this.

Code: Select all

int WaitTime = 60000;
var repo = SampleSolutionRepository.Instance;
var testDom = repo.testDom;
testDom.Self.WaitForDocumentLoaded(WaitTime);
Alternatively, use a Validate.Exist method on an element (the timeout can be set on the element's properties).

I hope this helps and points you in the right direction.

Cheers,
-Ned
.
Image

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: WaitForDocumentLoaded function???

Post by Vaughan.Douglas » Thu May 18, 2017 1:59 pm

I always add the status attribute to the DOM Rx Path example:

Code: Select all

/dom[@domain='test.com'  and @status='complete']
Although I don't know if this actually does the same thing as you're looking for, it does help with overall stability though.
Doug Vaughan

ngrishakin
Posts: 42
Joined: Fri Oct 04, 2013 9:47 pm

Re: WaitForDocumentLoaded function???

Post by ngrishakin » Thu May 18, 2017 5:23 pm

Ned and Vaughan.Douglas thank you so much for answers. I'm not using Repo only API calls.
So WaitFor is not available for me. I have to replace it with "TryFindSingle" routine.
Just wonder if I can do the following

Code: Select all

int WaitTime = 60000;
Host.Current.OpenBrowser("https://test.com", "ie");
WebDocument webDocument = Host.Current.FindSingle("/dom[@domain='test.com' and @status='complete']", WaitTime);
Thanks a lot again!!!
Nik

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: WaitForDocumentLoaded function???

Post by Vaughan.Douglas » Thu May 18, 2017 6:11 pm

I think it's worth a shot.
Doug Vaughan

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

Re: WaitForDocumentLoaded function???

Post by Support Team » Thu May 18, 2017 7:13 pm

ngrishakin wrote: Just wonder if I can do the following
This is bypassing the use of a Ranorex Repository, so it should work for you.

Kind Regards,
Ned
.
Image

ngrishakin
Posts: 42
Joined: Fri Oct 04, 2013 9:47 pm

Re: WaitForDocumentLoaded function???

Post by ngrishakin » Thu May 18, 2017 8:32 pm

Thank you so much for all your help. I had to make a little changes. My Ranorex is 6.1:

Code: Select all

            Host.Local.OpenBrowser("https://test.com/", "ie");
            webDocument = Host.Local.FindSingle("/dom[@domain='test.com' and @State='complete']", Global.WaitTime);
            webDocument.WaitForDocumentLoaded(Global.WaitTime);