Selenium RC we became quite used to using methods like iSElementPresent and waitForCondition/waitForPageToLoad to deal with Ajax and page loading events. With WebDriver we have to write them ourselves.
There are 4 important things going on here. In order:
There are 4 important things going on here. In order:
- Setting implicity_wait to 0 so that WebDriver does not implicitly wait.
- Returning True when the element is found.
- Catching the NoSuchElementException and returning False when we discover that the element is not present instead of stopping the test with an exception.
- Setting implicitly_wait back to 10 after the action is complete so that WebDriver will implicitly wait in future.
Method
isElementPresent(WebDriver driver,By by)
{
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
try
{
driver.findElement(by);
return true;
}
catch(Exception e)
{
return false;
}
finally
{
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
}
Regards,
Santosh.
hi i want to like this
ReplyDeleteIn selenium:
if(selenium.isElementPresent("")
{
//actions
}
In webdriver:
driver.findElement(By.id("")).isSelected or Enabled or Displayed)
{
//actions
}
which i can use select or displayed or enabled
Plz inform to me. It's urgent.