Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Drop Down Menu Test Selenium C# Code

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;

namespace SeleniumTests
{
    [TestFixture]
    public class DropDownMenuTest
    {
        private IWebDriver driver;
        private StringBuilder verificationErrors;
        private string baseURL;
       
        [SetUp]
        public void SetupTest()
        {
            driver = new FirefoxDriver();
            baseURL = "http://seleniummaster.com";
            verificationErrors = new StringBuilder();
        }
   

   
        [TearDown]
        public void TeardownTest()
        {
            try
            {
                driver.Quit();
            }
            catch (Exception)
            {
                // Ignore errors if unable to close the browser
            }
            Assert.AreEqual("", verificationErrors.ToString());
        }
       
        [Test]
        public void TheDropDownMenuTest()
        {
            driver.Navigate().GoToUrl(baseURL + "/sitecontent/seleniummenutest/seleniummenutest.html");
            HoverMasteringSeleniumLink();

            driver.FindElement(By.LinkText("Selenium IDE")).Click();
            driver.Navigate().Back();
            HoverMasteringSeleniumLink();

            driver.FindElement(By.LinkText("Selenium RC")).Click();

            driver.Navigate().Back();
            HoverMasteringSeleniumLink();

 

            driver.FindElement(By.LinkText("Selenium Grid")).Click();
            driver.Navigate().Back();
            HoverMasteringSeleniumLink();

 

            driver.FindElement(By.LinkText("Selenium Server")).Click();
            driver.Navigate().Back();
            driver.FindElement(By.LinkText("Go Back to the Main Page")).Click();
        }

private voidHoverMasteringSeleniumLink()
{
   
Actions builder =newActions(driver);

   
IWebElement elem = driver.FindElement(By.XPath("//p[contains(text(),'Mastering Selenium')]")); //Find the Root of the Menu
    builder
.MoveToElement(elem).Build().Perform();//Move mouse over to the Mastering Selenium Menu

}

       private bool IsElementPresent(By by)
        {
            try
            {
                driver.FindElement(by);
                return true;
            }
            catch (NoSuchElementException)
            {
                return false;
            }
        }
    }
}