How do I simulate Ctrl + V

2,518 views
Skip to first unread message

ei0haro

unread,
Mar 24, 2011, 11:04:41 AM3/24/11
to webdriver
Hi!

I need to paste some text from the clipboard to a textbox but have not
succeded.

I have tried this with no luck.

var webDriver = new FirefoxDriver { Url = "someUrl" };
webDriver.FindElement(By.Id("someTextBoxId")).Click();
webDriver.Keyboard.PressKey(Keys.LeftControl);
webDriver.Keyboard.PressKey("v");

Any other ideas?

Binod Pant

unread,
Mar 27, 2011, 9:49:48 AM3/27/11
to <webdriver@googlegroups.com>
Did you try
SendKeys(Keys.Chord(Keys.Control,"c"))


-Binod

> --
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
>

darrell

unread,
Mar 27, 2011, 2:22:35 PM3/27/11
to webdriver
The clipboard is an operating system concept and not really part of
the web page. I would suspect that using Selenium to send a ctrl-v
would send it to the web page, bypassing the operating system.
Additionally, ctrl-v means something different on Mac OS X and can
mean something different on Linux (depending on the windows management
system you are using and how the user has it configured). If you ever
decide to test on something other than Windows you will need to make
changes to your test case.

I know that Java has support for interacting with the clipboard. If
programming in Java, you could use the clipboard support to get the
object from the clipboard then use sendKeys to send it to the web
page. This will work better for all operating systems and avoid and OS
versus web page issues.

If you are not using Java then check and see if there is some support
for clipboard in the libraries of the language you are using.

Darrell

Simon Stewart

unread,
Mar 28, 2011, 6:39:18 AM3/28/11
to webd...@googlegroups.com
If you're using native events, this should work as expected, but be
aware that your tests might be fragile if something else puts content
into the clipboard.

Simon

Reply all
Reply to author
Forward
0 new messages