Sunday, 16 March 2014

How to verify if button is enabled in Selenium Webdriver in C#.Net?

Below example in C#.Net illustrates how we can verify if the button is enabled or disabled.


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 driver=null;
try
{

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

driver.Url = "http://register.rediff.com/register/register.php";
              driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));

driver.Navigate();

//get the button

IwebElement e1 = driver.FindElement(By.XPath ("//input[@value='Check Availability']"));

//verify the button's Enabled property

if (e1.Enabled)
Console.WriteLine("Button is enabled");
else
Console.WriteLine("Button is disabled");

}

 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