Reputation: 523
In Selenium WebDriver+Java+Junit. I have the following method to assert that element is not present.
public boolean AssertDetailNotPresent(){
if (driver.findElements(linkDetail).size()==0) return true;
else return false;
}
I want test to fail
if it is present, but it passes(
Can anyone help, why it passes? (element is present).
Upvotes: 0
Views: 419
Reputation: 193078
With out any visibility to your Usecase it is tough to understand why you are trying to validate a False-Positive scenario. But still to assert that an element as identified by linkDetail
is present or not you can use the following code block :
public boolean AssertDetailNotPresent()
{
if (driver.findElements(linkDetail).size() > 0)
return false;
else
return true;
}
Note : The outcome of this function would depend a lot on the defination of linkDetail. If somehow linkDetail matches any of the nodes you are bound to get the
return
as false else true will be returned.
Upvotes: 1