Hello all I am using webdriver so if I want to use selenium;s rc function isElementPresent I have to emulate selenium rc so I do something like this:
import org.
Not a part of Selenium 2, you can do the following:
// Use Selenium implementation or webdriver implementation
Boolean useSel = false;
/**
* Function to enable us to find out if an element exists or not.
*
* @param String An xpath locator
* @return boolean True if element is found, otherwise false.
* @throws Exception
*/
public boolean isElementPresent(String xpathLocator) {
return isElementPresent(xpathLocator, false, "");
}
/**
* Function to enable us to find out if an element exists or not and display a custom message if not found.
*
* @param String An xpath locator
* @param Boolean Display a custom message
* @param String The custom message you want to display if the locator is not found
* @return boolean True if element is found, otherwise false.
* @throws Exception
*/
public boolean isElementPresent(String xpathLocator, Boolean displayCustomMessage, String customMessage) {
try {
if (useSel) {
return sel.isElementPresent(xpathLocator);
} else {
driver.findElement(By.xpath(xpathLocator));
}
} catch (org.openqa.selenium.NoSuchElementException Ex) {
if (displayCustomMessage) {
if (!customMessage.equals("")) {
System.out.print(customMessage);
}
} else {
System.out.println("Unable to locate Element: " + xpathLocator);
}
return false;
}
return true;
}