With WebDriver from Selenium 2.0a2 I am having trouble checking if an element is visible.
WebDriver.findElement returns a WebElement<
I have the following 2 suggested ways:
You can use isDisplayed() as below:
driver.findElement(By.id("idOfElement")).isDisplayed();
You can define a method as shown below and call it:
public boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
}
catch (org.openqa.selenium.NoSuchElementException e) {
return false;
}
}
Now, you can do assertion as below to check either the element is present or not:
assertTrue(isElementPresent(By.id("idOfElement")));