We can double click the elements using Actions class in selenium webdriver in C#.
Below class/Interface must be imported before performing double click in Selenium Webdriver.
using OpenQA.Selenium; using OpenQA.Selenium.Interactions; using OpenQA.Selenium.Interactions.Internal; using OpenQA.Selenium.Support.UI;
Then You will have to create the instance of Actions class and use below code to perform doubleclick operation.
//create Actions object
Actions builder = new Actions(driver);
//create a chain of actions builder.DoubleClick().Build().Perform();
Complete Example in C#.Net to perform doubleclick operation is given below
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Chrome; using OpenQA.Selenium.IE; using OpenQA.Selenium.Support.UI; using System.Collections.ObjectModel; using OpenQA.Selenium.Interactions; using OpenQA.Selenium.Interactions.Internal; using OpenQA.Selenium.Support.UI; namespace Abc { class Program { static void Main(string[] args) { IWebDriver driver=null; try { driver = new ChromeDriver(@"F:\selenium\csharp"); driver.Url = "http://www.google.co.in"; driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20)); driver.Navigate(); //create Actions object Actions builder = new Actions(driver); IWebElement e1 = driver.FindElement(By.Name("source")) //use DoubleClick method to double click on any element builder.DoubleClick(e1).Build().Perform(); } catch(Exception e){ Console.WriteLine("Exception ******"+e.ToString()); } finally{ Thread.Sleep(2000); driver.Quit(); Console.ReadLine(); } } } }
What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com
Thank you
ReplyDeleteThank you
ReplyDeleteIf we don't know Element info. Then how we do click using coordinates
ReplyDeleteThank you so much! This helped me a lot :)
ReplyDelete