Selenium: How to prepend data to a text box or text Area

selenium, selenium-webdriver

Solution

import org.openqa.selenium.Keys;

...

WebElement element = driver.findElement(By.xpath("textBox/textarea"));
element.sendKeys(Keys.HOME + "abc");

or may be for multiline text areas

element.sendKeys(Keys.CONTROL, Keys.HOME);
element.sendKeys("abc");

Problem

I am using Selenium Web driver. I have a Text Area where some text is written. Now How can I prepend some text/html in it or inserting a data at a specific location? The following code appends it to the text Area/ Text Box ``` driver.findElement(By.xpath("textBox/textArea")).sendKeys("abc"); ``` ie. if the text area/ text box contains 123. The result of above would be 123abc. But I want abc123 or 12abc3 PS: I am testing an "Email Reply" functionality. So as a user, when you reply to a mail, you do not do copy text, then clear all text then copy all the text back after writing the new text like below: ``` WebElement element = driver.findElement(By.xpath("textBox/textarea")); String previousText = element.getAttribute("value"); element.clear(); element.sendKeys("abc" + previousText); ``` Please help...

Original source