Sunday 16 March 2014

How to verify if the element is displayed or not using Selenium Webdriver in C#.Net?

We can check if the element is displayed or not using Displayed property in C#.Net. 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using OpenQA.Selenium;

using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
using System.Collections.ObjectModel;

namespace Abc
{
    class Program
    {
        static void Main(string[] args)
        {

            //IWebDriver x = new InternetExplorerDriver(@"F:\selenium\csharp");
            //IWebDriver x = new FirefoxDriver();
            IWebDriver driver=null;
            try
            {

                //launch selenium browser 
                driver = new ChromeDriver(@"F:\selenium\csharp");

                driver.Url = "http://register.rediff.com/register/register.php";

                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
                driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(50));
                driver.Manage().Window.Maximize();
                 
                //navigate to url 
                driver.Navigate();

                IWebElement e=null;

                Thread.Sleep(5000);

                //verify if checkbox is displayed or not.

                e = driver.FindElement(By.Name("chk_altemail"));

                Console.WriteLine("Checkbox is displayed?" + e.Displayed);

                Console.ReadLine();

            }

            catch(Exception e){

                 Console.WriteLine("Exception ....*********"+e.ToString());
               
            }
           
            finally{
            Thread.Sleep(2000);
            driver.Quit();
            Console.ReadLine();
            }

           
        }
    }
}



What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com

No comments:

Post a Comment

Buy Best Selenium Books

Contributors