Actions 클래스를 사용하여 Selenium webdriver(C#)의 특정 위치 또는 요소로 마우스 포인터를 이동할 수 있습니다. 먼저 이 클래스의 개체를 만들어야 합니다.
요소를 이동하려면 MoveToElement 메서드를 적용하고 요소 로케이터를 이 메서드의 매개변수로 전달해야 합니다. 마지막으로 이 작업을 실제로 수행하려면 Perform 메서드를 사용해야 합니다.
요소로 이동한 후 Click 메서드를 사용하여 요소를 클릭할 수 있습니다. 특정 위치로 이동하려면 MoveByOffset 메서드를 사용한 다음 x 및 y 축을 따라 이동할 오프셋 번호를 매개변수로 전달해야 합니다.
구문
Actions a = new Actions(driver);
a.MoveByOffset(10,20).Perform();
a.Click().Perform()
//move to an element
IWebElement l = driver.FindElement(By.name("txtnam"));
a.MoveToElement(l).Perform(); 라이브러리 링크로 마우스를 이동한 다음 클릭해 보겠습니다.

예
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
namespace NUnitTestProject2{
public class Tests{
String url = "https://www.tutorialspoint.com/index.htm";
IWebDriver driver;
[SetUp]
public void Setup(){
//creating object of FirefoxDriver
driver = new FirefoxDriver("");
}
[Test]
public void Test2(){
//URL launch
driver.Navigate().GoToUrl(url);
//identify element
IWebElement l = driver.FindElement(By.XPath("//*[text()='Library']"));
//object of Actions class
Actions a = new Actions(driver);
//move to element
a.MoveToElement(l);
//click
a.Click();
a.Perform();
Console.WriteLine("Page title: " + driver.Title);
}
[TearDown]
public void close_Browser(){
driver.Quit();
}
}
} 출력
