Sometimes a tester
wants to mouse hover on an object instead of clicking it. It can be done with
the help of Action class. Let’s try it.
Step 1: Create a new
project and add a new item “Basic Unit Test”.
Step2: Add the following code into it.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium;
using System.Threading;
namespace UnitTestProject2
{
[TestClass]
public class ActionClass
{
[TestMethod]
public void Test_Action()
{
FirefoxDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.snapdeal.com/");
driver.Manage().Window.Maximize();
Actions a1 = new Actions(driver);
a1.MoveToElement(driver.FindElement(By.XPath(".//*[@id='leftNavNemu']/div/div[1]/ul/li[3]/a/span[1]"))).Build().Perform();
Thread.Sleep(3000);
Actions a2 = new Actions(driver);
a2.MoveToElement(driver.FindElement(By.XPath(".//*[@id='leftNavNemu']/div/div[1]/ul/li[3]/div/ul/li[3]/a/span[1]"))).Build().Perform();
Thread.Sleep(3000);
Actions a3 = new Actions(driver);
a3.MoveToElement(driver.FindElement(By.XPath(".//*[@id='leftNavNemu']/div/div[1]/ul/li[3]/div/ul/li[3]/div/div/ul/li/div[1]/div/form/div[1]/p[2]/a"))).Click().Perform();
Thread.Sleep(3000);
}
}
}
Step 3: Execute it and it is done.
No comments:
Post a Comment