Majkl Majkl - 9 months ago 45
C# Question

How to find element that should not be there in c# Selenium drivers

I'm using Firefox Selenium webdrivers and Visual studio with C#.

I need to check if exists element that should not be there.

For example, in the pop-up menu are 3 elements:


I have created test case to check these elements.

In the new build of tested software, by mistake, in the popup menu are 4 elements now.


How to write to created test case that element04 should not be there ?

How to check element04 that should not be there ?

Thank you for help.


In addition to checking the presence of your elements 01 through 03, also check the number of elements in the pop up menu (as mentioned by @Grasshopper's comment) :

var driver = new FirefoxDriver(); 

var elements = driver.FindElements(By.Id("yourPopUpMenuId"));
Assert.AreEqual(3, elements.Count);

Checking the number of elements present assures you that there are no more than expected and you probably don't know what name the additional erroneous elements will have.