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”

thanks
Hi Pavandeep,
Thanks, It works fine for me.
[...] Selenium Command waitForElementPresent waits till a particular element shows up on the page. The other option is waitForCondition(locator) [...]
catch (Exception), if it is for Java then it should
catch (Exception e)