How to press Ctrl+V in Selenium WebDriver

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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:UsersusDocumentsVisual Studio 2012ProjectsSeleniumTestsSeleniumTeststest.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





Your code works fine for me. Are you sure there's something in your clipboard?
– Yi Zeng
Aug 19 '13 at 21:01





yes, I selected text before running this code.
– vmg
Aug 19 '13 at 21:04





What OS/Browser have you used?
– vmg
Aug 19 '13 at 21:07




2 Answers
2



Here's what I would suggest:


IWebDriver webDriver = new InternetExplorerDriver();
webDriver.Navigate().GoToUrl(@"C:UsersusDocumentsVisual Studio 2012ProjectsSeleniumTestsSeleniumTeststest.html");
var el = webDriver.FindElement(By.XPath(".//*[@id='fld']"));
el.Click();
el.SendKeys(Keys.CONTROL+ "v");

webDriver.Quit();





it worked. thanks! Strange though: I tried this before posting this question and it didn't work for me :) Maybe I missed something because I checked lots of different approaches. Anyway, thank you!
– vmg
Aug 19 '13 at 21:04





You are very welcome, glad it worked.
– Richard
Aug 19 '13 at 21:04





@Vitaliy: It might be because you used a capital "V". For some reason capital letters don't work.
– Meta-Knight
Mar 6 '14 at 15:13





I think, Ctrl + capital 'V' doesn't work, because 'V' = Shift + 'v' in webdriver, and total sequence is: Ctrl + Shift + v
– Dmitriy L
Sep 11 '15 at 13:05





You can try this simple way


driver.findElement(By.xpath(FileUpDownLoad._SOURCE_NAME)).sendKeys(Keys.CONTROL + "v");






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

JDyP xUJyuzEPK2sq7,OsmA6mGfpJnEHBFp9X1COZfD O74lid9OlSC8P9HAuI x9Vl2siot0jtL,78cpe3o D a4T,QHI
F56,EuBj4 l35kOsrJ2Wpey23k25M3zBMe,oOVr 0ayi

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Current 93