I'm using Selenium Web Driver (Java, Chrome Browser). I would like to enter a tab character into a text area. By default, entering a tab character causes the next input to be focused, but I actually want the tab character to be printed into the textarea input.
Since my tests are running on a windows machine, I thought I could use the alt-code to enter the tab. IE
- Hold alt
- Press 0
- Press 9
- Release alt
But I'm not sure how to do this programmatically with WebDriver. I tried the following:
WebElement myTextArea = driver.findElement(By.cssSelector("form textarea"));
myTextArea.sendKeys("before_tab", Keys.chord(Keys.ALT, Keys.NUMPAD0, Keys.NUMPAD9), "after_tab");
...but it just printed "before_tabafter_tab" into the text area, I guess because it's pressing ALT, 0, and 9 all at the same time which doesn't translate to a printable character.
I would also consider pasting either via keyboard shortcut or context menu (this is actually closer to how I expect the user to enter text into the textarea), but I can't see how to put the text onto the clipboard for the selenium-driven browser to access.
Any help would be appreciated.