Use of Action Class with C#

Action Class is an advance webdriver API . By using action class methods user can interact below events:

Mouse Movement
Right Click
Drag & Drop
Double Click
Keyboard operation

Steps to follow Mouse movement operation:


Find a web element in UI where you need to perform mouseover operation.
Create an object of Action class & pass driver instance as an argument.
Ex:
                 Actions act = new Actions(driver);
         
Perform mouse movement operation using "MoveToElement()" method.
Also we can use Perform() method.
Ex:

Actions actions = new Actions(driver);
IWebElement ele = driver.FindElement(By.Id("dropdown ID"));
actions.MoveToElement(ele);

IWebElement ele1 = driver.FindElement(By.Id("sub option ID"));
actions.MoveToElement(ele1);
actions.Click().Build().Perform();

Working with Keyboard operation :

IWebDriver  driver = new ChromeDriver();
driver.Navigate().GoToUrl("www.facebook.com");
driver.FindElement(By.Id("username")).SendKeys("xxxx");
driver.FindElement(By.Id("password")).SendKeys("xxxx");
Actions actions = new Actions(driver);
actions.SendKeys(Keys.Enter).Perform();


Question
1. Without using Click() ,how to click the buttons?
Ans. By using Submit() method.

Drag & Drop scenario :

namespace DemoAutomation
{
public class DragNDropSample {
 IWebDriver driver;
  @Test
 public void DragAndDrop() {
  driver = new FirefoxDriver();
Actions actions = new Actions(driver);
 driver.Navigate().To("www.someurl.com");
                IWebElement Source = driver.findElement(By.cssSelector("source place"));
                IWebElement target = driver.findElement(By.cssSelector("destination place"));
                actions.DragAndDrop(source, target).Build().Perform();
 }
}
}

Some More Action Class functions:


ClickAndHold()
ContextClick()
DoubleClick()

Copyright © 2017 qatoolsguide.blogspot.com || ALL RIGHTS RESERVED