From the syntax it looks like you are using C# bindings. I use the
Java bindings so this might not be 100% accurate.
The driver.FindElement(by) will return a WebElement object.
The .Displayed property will tell you if the element is visible to the
user. At this point it is assumed the element exists. Before you see
if the element is visible, you need to see if the element exists. The
Java binding will throw an exception if you attempt to find an element
and it does not exist. To handle this I wrap the findElement call in a
try/catch block. If the element does not exist, the catch body is
executed. In the catch body I would save that the element does not
exist. You need to do something similar in C#. For example, in Java:
boolean visible = false; // assume it is invisible
try {
// try to find the element
WebElement w = driver.FindElement(by);
// if I get to here the element exists
// if it is visible
if(w.Displayed)
visible = true;
} catch(Exception e) {
}
Assert.IsFalse(visible);
This is something like what you need. There are probably small syntax
errors because I'm not a C# programmer.