Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to press Ctrl+V in Selenium WebDriver

In one of my automated tests I need to press Ctrl+V in text box to paste text in it. But I can't do that. I'm using Selenium WebDriver for .net v. 2.35.0.0. Here is my code, it does not work. It presses Ctrl and then V, but text not gets pasted in the box:

IWebDriver webDriver = new InternetExplorerDriver();
            webDriver.Navigate().GoToUrl(@"C:\Users\us\Documents\Visual Studio 2012\Projects\SeleniumTests\SeleniumTests\test.html");
            var el = webDriver.FindElement(By.XPath(".//*[@id='fld']"));
            el.Click();
            Actions builder = new Actions(webDriver);
            builder.KeyDown(el, Keys.LeftControl).Perform();
            builder.SendKeys(el, "v").Perform();
            builder.KeyUp(el, Keys.LeftControl).Perform();

            webDriver.Quit();

Update: OS: Windows Server 2012, x64 Browser: IE10

like image 968
vmg Avatar asked Aug 19 '13 20:08

vmg


1 Answers

Here's what I would suggest:

IWebDriver webDriver = new InternetExplorerDriver();
webDriver.Navigate().GoToUrl(@"C:\Users\us\Documents\Visual Studio 2012\Projects\SeleniumTests\SeleniumTests\test.html");
var el = webDriver.FindElement(By.XPath(".//*[@id='fld']"));
el.Click();
el.SendKeys(Keys.CONTROL+ "v");

webDriver.Quit();
like image 157
Richard Avatar answered Dec 02 '22 02:12

Richard