Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send key chords to text area with Selenium?

I would like to simulate a user pressing shift-enter in a text area. Here is the code I am working with:

var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://pagewithtextarea");
var textarea = driver.FindElement(By.Id("myTextArea"));
//Send text
textarea.SendKeys("hello world!");

If I want to simulate pressing the enter button I can say:

textarea.SendKeys(Keys.Enter);

How could I simulate pressing shift and enter at the same time?

like image 750
Corey Sunwold Avatar asked Jan 07 '12 00:01

Corey Sunwold


2 Answers

Simpler than I expected. Since SendKeys takes a string, and the static constants on Keys are all strings they can simply be concatenated together like this:

textarea.SendKeys(Keys.Shift + Keys.Enter);
like image 181
Corey Sunwold Avatar answered Nov 03 '22 23:11

Corey Sunwold


for me, on c# only this variation works:

actions.KeyDown(Keys.Control);
actions.SendKeys("a");
actions.KeyUp(Keys.Control);
like image 34
Tomas Avatar answered Nov 03 '22 21:11

Tomas