Selenium2/WebDriver is optimized for positive testing paths. My web application hides elements based on user permissions. I am looking for an element and throwing-catching the exception when it does not find it and the command fails (I'm using Java). This verifies the element is not present. I've seen this question: Quicker way to assert that an element does not exist but I am wondering if there is an alternative way besides if/else statements.
Edited: The code currently being used is shown below. This currently takes ~60+ seconds to run.
@User246: I guess my main question is there a parameter or something like that to pass to Selenium that tells it to only look for the WebElement for X seconds before throwing the exception. Optimally I would set it to 1 second since I expect it to not be found and just want to catch the exception. I hope this is more clear.
protected void assertAddButtonIsHidden() throws Exception
{
boolean found = true;
try
{
WebElement addButton = findElementById("add");
addButton.click();
}
catch (StaleElementReferenceException x)
{
found = false;
}
assertTrue(!found);
}
assertAddButtonIsHidden
just once takes 60 seconds?