Explaining how the real world works!     RSS Feed The Automated Tester on Twitter The Automated Tester on LinkedIn The AutomatedTester on github

Selenium waitForX Tutorial

Sat 12 Jul 2008

In the tutorials so far we have learnt how to record and play them back and have learnt how to lever XPaths to find items that we couldn't normally find. From there the next thing that would be needed to make sure that you script works well in an AJAX environment.

Lets start by creating a new script to test this page.



You would have noticed that the page that you were testing was not actually visible when the test started. That means when the test started Selenium could not hook into the page and work against it straight away. I have created an example here of what Selenium IDE would have recorded. This is not really what we want as the test would always fail because of the loading page. So how would we get around this? Well the answer is to use waitForX (waitForElement,waitForEval,etc) commands. To get Selenium to work properly on that page you will need to put a waitForX command to catch one of the buttons or text boxes. I have created an example script here so that you can see how it is done by waiting for new elements to load.

Another useful approach is to wait for the loading page to disappear. I have found this extremely useful when testing editors because all the buttons have loaded but AJAX is still bringing the content down from the machine.I have created an example of this can be found here.

Another useful waitFor command is the waitForEval. This command will wait for when a javascript is the same as a pattern. This means that if we wanted something to wait for a certain value then it would run.

The waitForX commands become invaluable when testing AJAX applications because you never really know how long it will take to load elements to the page.

    Area: tutorials

blog comments powered by Disqus