I am writing a method in Java using Selenium WebDriver methods, to test if an element is present or not in a webpage.
Below is my piece of code:
public boolean waitForElementPresent(String target) {
if(target!=null) {
driver.manage().timeouts()
.implicitlyWait(15, TimeUnit.SECONDS);
try {
if (driver.findElement(By.name(target))!=null) { log.info("Entered name Condition"); return true; }
} catch(Exception e) { log.debug(e); return false; }
} else {
log.info("The target is null");
return false;
}
}
Here the target being sent is "name=go"
, this target is captured by using selenium IDE. Even though the page is completely loaded and is displaying this particular element, my method is failing with the message 'ERROR: Could not find the Element in the specified time'.