Selenium WebDriver (C#)-এ Actions ক্লাস ব্যবহার করে মাউস পয়েন্টার নির্দিষ্ট লোকেশন বা এলিমেন্টে সরানো যায়। প্রথমে এই ক্লাসের একটি অবজেক্ট তৈরি করতে হবে।
এরপর একটি এলিমেন্টে সরাতে 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();চলুন মাউসকে Library লিংকে সরিয়ে সেটিতে ক্লিক করি।

উদাহরণ
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(); } } }আউটপুট
