I was automating Gmail to send a mail with attachment. The mail contains the in-build signature text of the sender. Every time when I want to type anything in the mail body, the text appears always after the "Regards" and name field. Below is my code.
driver.findElement(By.xpath(".//*[text()= 'COMPOSE']")).click();
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//textarea[contains(@aria-label, 'To')]")));
driver.findElement(By.xpath(".//textarea[contains(@aria-label, 'To')]")).click();
driver.findElement(By.xpath(".//textarea[contains(@aria-label, 'To')]")).sendKeys("[email protected]");
driver.findElement(By.name("subjectbox")).click();
driver.findElement(By.name("subjectbox")).sendKeys("efgh");
driver.findElement(By.xpath("(.//*[@aria-label='Message Body'])[2]")).click();
driver.findElement(By.xpath("(.//*[@aria-label='Message Body'])[2]")).sendKeys("This is an auto-generated mail");
One solution I am using is as below:
driver.findElement(By.xpath("(.//*[@aria-label='Message Body'])[2]")).click();
String s = "Sir,\n This is a auto generated email. \n\n"
+ driver.findElement(By.xpath("(.//*[@aria-label='Message Body'])[2]")).getText();
driver.findElement(By.xpath("(.//*[@aria-label='Message Body'])[2]")).clear();
driver.findElement(By.xpath("(.//*[@aria-label='Message Body'])[2]")).sendKeys(s);
instead of these two line: driver.findElement(By.xpath("(.//[@aria-label='Message Body'])[2]")).click(); driver.findElement(By.xpath("(.//[@aria-label='Message Body'])[2]")).sendKeys("This is an auto-generated mail");
But this solution actually removes all the format of that signature text. Even with signature text, I am not able to get the xpath of the text box using Firebug, I have to delete the complete signature text to get those. I am a beginner in this automation field. Please help how can I write the text in the mail body before the signature text.

