Using Selenium WaitForCondition 

In this example I will tell you how you can use selenium WaitForCondition command. Below is the code for waitForElementPresent. You can do the same with WaitForCondition and pass the element id.
Here I will waiting for element “//div[@id='ctl00_contentSection_LoginPanel']/h2″ then once the element is found continue with testing other things.
This is waitForElementPresent code for element “//div[@id='ctl00_contentSection_LoginPanel']/h2″

for (int second = 0;; second++) {
if (second >= 60) Assert.Fail("timeout");
try
{
if (selenium.IsElementPresent
("//div[@id='ctl00_contentSection_LoginPanel']/h2"))
break;
}
catch (Exception)
{}
Thread.Sleep(1000);
}

Alternatively you can use WaitForCondition command and to do the same thing as waitForElementPresent but in a single line.

selenium.WaitForCondition("selenium.isElementPresent
(\"//div[@id='ctl00_contentSection_LoginPanel']/h2\")", "60000");

Thought the code is in C# the command that we are using is selenium.isElementPresent which is Java selenium command. If you use selenium.IsElementPresent you will get the following error “Selenium.SeleniumException : selenium.IsElementPresent is not a function”


Author: Pavandeep Puddupakkam on October 26, 2010
Category: Selenium RC
Tags: ,
Google Webdriver Forum -The Online Community for Google Webdriver and Selenium RC Users and Professionals
4 responses to “Using Selenium WaitForCondition”
  1. Venkat says:

    thanks

  2. Sobeer Singh says:

    Hi Pavandeep,
    Thanks, It works fine for me.

  3. [...] Selenium Command waitForElementPresent waits till a particular element shows up on the page. The other option is waitForCondition(locator) [...]

  4. Dipen says:

    catch (Exception), if it is for Java then it should
    catch (Exception e)

Leave a Reply

Last articles