How to check if Element exists in c# Selenium drivers? (2024)

Table of Contents
Example Output

We can check if element exists with Selenium webdriver in C#. This can be determined with the help of the FindElements method. It returns a list of elements which matches the locator passed as a parameter to that method.

If there are no matching elements, an empty list is obtained. In case we have used the method FindElement instead of FindElements, NoSuchElementException will be thrown if there are no matching elements.

For implementation we shall be using the NUnit framework.

Example

using NUnit.Framework;using OpenQA.Selenium;using OpenQA.Selenium.Chrome;using OpenQA.Selenium.Firefox;using System;using System.Collections.Generic;namespace NUnitTestProject1{ public class Tests{ String u = "https://www.tutorialspoint.com/about/about_careers.htm"; IWebDriver d; [SetUp] public void Setup(){ //creating object of FirefoxDriver d = new FirefoxDriver(); } [Test] public void Test1(){ //launching URL d.Navigate() .GoToUrl(u); //identify elements and store it in list List<IWebElement> e = new List<IWebElement>(); e.AddRange(d.FindElements (By.XPath("//*[text()='Terms of Use']"))); //checking element count in list if (e.Count > 0){ Console.WriteLine("Element is Present"); } else { Console.WriteLine("Element is not Present"); } } [TearDown] public void close_Browser(){ d.Quit(); } }}

Output

Click on Run All Tests

How to check if Element exists in c# Selenium drivers? (1)

Click on Open additional output for this result link −

How to check if Element exists in c# Selenium drivers? (2)

We should get the Test Outcome and Standard Output.

How to check if Element exists in c# Selenium drivers? (3)

Updated on: 30-Jan-2021

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started

How to check if Element exists in c# Selenium drivers? (5)

Advertisem*nts

How to check if Element exists in c# Selenium drivers? (2024)
Top Articles
Make Boxed Stock Taste Homemade With This Easy Trick
9 Types of Marketing to Promote Your Business | Mailchimp
Inducement Small Bribe
Jesus Calling December 1 2022
Crocodile Tears - Quest
Ou Class Nav
Sinai Web Scheduler
Snarky Tea Net Worth 2022
Lesson 3 Homework Practice Measures Of Variation Answer Key
Progressbook Brunswick
All Obituaries | Ashley's J H Williams & Sons, Inc. | Selma AL funeral home and cremation
Enterprise Car Sales Jacksonville Used Cars
Alexander Funeral Home Gallatin Obituaries
Driving Directions To Bed Bath & Beyond
Webcentral Cuny
Niche Crime Rate
Everything We Know About Gladiator 2
Foxy Brown 2025
Palm Springs Ca Craigslist
Universal Stone Llc - Slab Warehouse & Fabrication
All Breed Database
Hdmovie2 Sbs
3Movierulz
15 Primewire Alternatives for Viewing Free Streams (2024)
Spiritual Meaning Of Snake Tattoo: Healing And Rebirth!
United E Gift Card
The Hoplite Revolution and the Rise of the Polis
Pokemmo Level Caps
Petsmart Distribution Center Jobs
Senior Houses For Sale Near Me
Wildfangs Springfield
Restored Republic December 9 2022
Best Restaurant In Glendale Az
Gary Lezak Annual Salary
Omaha Steaks Lava Cake Microwave Instructions
Let's co-sleep on it: How I became the mom I swore I'd never be
What Is A K 56 Pink Pill?
SF bay area cars & trucks "chevrolet 50" - craigslist
Alston – Travel guide at Wikivoyage
2024-09-13 | Iveda Solutions, Inc. Announces Reverse Stock Split to be Effective September 17, 2024; Publicly Traded Warrant Adjustment | NDAQ:IVDA | Press Release
National Weather Service Richmond Va
Unlock The Secrets Of "Skip The Game" Greensboro North Carolina
Hdmovie2 Sbs
Suppress Spell Damage Poe
Ewwwww Gif
Fresno Craglist
Wera13X
The 5 Types of Intimacy Every Healthy Relationship Needs | All Points North
Otter Bustr
Mike De Beer Twitter
Thrift Stores In Burlingame Ca
Latest Posts
Article information

Author: Margart Wisoky

Last Updated:

Views: 6079

Rating: 4.8 / 5 (58 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Margart Wisoky

Birthday: 1993-05-13

Address: 2113 Abernathy Knoll, New Tamerafurt, CT 66893-2169

Phone: +25815234346805

Job: Central Developer

Hobby: Machining, Pottery, Rafting, Cosplaying, Jogging, Taekwondo, Scouting

Introduction: My name is Margart Wisoky, I am a gorgeous, shiny, successful, beautiful, adventurous, excited, pleasant person who loves writing and wants to share my knowledge and understanding with you.