Page 1 of 1

WaitForDocumentLoaded() Method and ElementNotFoundException

Posted: Thu Oct 15, 2009 8:35 am
by SvenP
Hello,

our company is evaluating Ranorex for Website (our created Websites, Webshops) GUI Tests . It´s a fine tool and most tests run well, BUT there is a main problem that occurs often.
I use WaitForDocumentLoaded(); after every performClick() method. But Ranorex dont wait long enough for the Page, so i get an ElementNotFoundException. The other Option is to use Delay.Ms();, but it´s not a good solution. So why does WaitForDocumentLoaded() not work correctly all the time. Sometimes it works, but when the page needs too much time for loading, the method doesnt work.

Example:

Code: Select all

repo.WebDocumentZeitschriften_Abopool.Warenkorb.PerformClick();
repo.WebDocumentWarenkorb_Minus_Zeitschr.Self.WaitForDocumentLoaded();

Report.Info("Es wird überprüft, ob die Zeitschrift '" + s + "' im Warenkorb liegt");
ImgTag InhaltWarenkorb = repo.WebDocumentWarenkorb_Minus_Zeitschr.SomeDivTag.FindSingle(".//img[@title='" + s + "']");
The Problem is that WebDocumentWarenkorb_Minus_Zeitschr wasnt found. if i use delay instead of repo.WebDocumentWarenkorb_Minus_Zeitschr.Self.WaitForDocumentLoaded(); it works. Sometimes it also work with WaitForDocumentLoaded() @ this example. Itßs a strange behaviour.

Thx for the help

Re: WaitForDocumentLoaded() Method and ElementNotFoundException

Posted: Thu Oct 15, 2009 10:41 am
by Support Team
The problem here is that the WaitForDocumentLoaded method is not even called if you get an ElementNotFoundException for the repo.WebDocumentWarenkorb_Minus_Zeitschr repository item. When you try to get the repo.WebDocumentWarenkorb_Minus_Zeitschr.Self repository item, Ranorex will search for an element with the path you specified for it, e.g. for a document with the specified title.

There are two ways how you can make your code work:
  1. Increase the Search Timeout of the repo.WebDocumentWarenkorb_Minus_Zeitschr repository item.
  2. If both repo.WebDocumentZeitschriften_Abopool and repo.WebDocumentWarenkorb_Minus_Zeitschr correspond to the same browser (tab), you can call WaitForDocumentLoaded on the previous web document, too, i.e. on the repo.WebDocumentZeitschriften_Abopool repository item.
Regards,
Alex
Ranorex Support Team

Re: WaitForDocumentLoaded() Method and ElementNotFoundException

Posted: Thu Oct 15, 2009 12:53 pm
by SvenP
Hello,

thx for the clue. i think searchtimeout will solve the problem, but can i use this function also for variables that are not in the repository. because sometimes i need not hard coded values like this

Code: Select all

public static WebDocument Zeitschriften;
....

Zeitschriften = "/dom[@caption~'^" + x3 + y2 + "']";

Re: WaitForDocumentLoaded() Method and ElementNotFoundException

Posted: Thu Oct 15, 2009 1:15 pm
by Support Team
You can, use the following syntax:
Zeitschriften = Host.Local.FindSingle("/dom[@caption~'^" + x3 + y2 + "']", 5000);
Regards,
Alex
Ranorex Support Team

Re: WaitForDocumentLoaded() Method and ElementNotFoundException

Posted: Thu Oct 15, 2009 1:30 pm
by SvenP
thanks a lot. i will try this.