Scenario:
Open gmail.comEnter username
Enter Password
Click on SignIn
Click on composeButton
Add recipent
Add Subject
Click on attachment
Add your File location
Click on Send Button
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
public class SendFile {
public static void main(String str[]) throws InterruptedException, AWTException{
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.gmail.com/");
//open gmail
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='Email']")).sendKeys("enteryouremailid");
//enter emailid
driver.findElement(By.xpath(".//*[@id='Passwd']")).sendKeys("enteryourpassword");
// enter password
driver.findElement(By.xpath("//*[@id='signIn']")).click();
//click on sign in
driver.findElement(By.xpath("//div[contains(text(),'COMPOSE')]")).click();
//click on compose button
driver.findElement(By.xpath("//form[1]//textarea[1]")).sendKeys("ritu7181@gmail.com");
//enter email id where you need to send email
driver.findElement(By.xpath("//div[@class='aoD az6']//input[@class='aoT']")).sendKeys("Please find attachment");
//Enter subject
Thread.sleep(15000);
driver.findElement(By.xpath("//div[@class='a1 aaA aMZ']")).click();
//click on attachment icon
StringSelection ss = new StringSelection("C:\\Users\\Ritika Gulati\\Downloads\\Asp.docx");
//upload your file using RobotClass
//attach your path where file is located.
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
Robot robot = new Robot();
Thread.sleep(5000);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_V);
Thread.sleep(6000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
Thread.sleep(10000);
driver.findElement(By.xpath("//div[text()='Send']")).click();
//Click on send
}
}




What is ROBOt Class? Can you please explain
ReplyDeletehttp://www.seleniumgyan.com/2014/11/how-to-upload-file-in-selenium.html
ReplyDeleteC:\\Users\\Ritika Gulati\\Downloads\\Asp.doc this path is not taken by selenium shopowing error
ReplyDeletei should only enter name of file : asp.doc which should be in desktop.
Deleteit's working
One of the best email services of today, and probably also the one with largest user base is Gmail, a free web-based service that is powered by Google. Being associated with this internet giant gives Google an edge over the rest with so many features that come added to it.
ReplyDeleteways to consult gmail
thanks is working fine
ReplyDeleteThanks a lot . Working fine. :)
ReplyDeleteGmail account is featured with many unique features which can cause several problems at the time of account login or use of internal services. hotmail.com
ReplyDeletehow you generate attachment icon xpath.
ReplyDeletereally you have posted an informative blog. it will be really helpful the peoples who are all working under the technology. thank you for sharing this blog.
ReplyDeleteselenium training in chennai
such an interesting article you have been shared. really it will be useful to many peoples. thank you for sharing such kind of an interesting article.
ReplyDeleteandroid training in chennai
good job..keep it up :)
ReplyDeleteuseful information on topics that plenty are interested on for this wonderful post.Admiring the time and effort you put into your b!.. Odisha Ration Card Download
ReplyDeleteGood content i learn lot of thinks.
ReplyDeleteHadoop online Training\Informatica Online Training\ETL Testing Online Training
It's True information.Thanks to sharing.
ReplyDeleteUNIX Shell scripting training in chennai\ORACLE apps finance training in chennai
Hats off to your presence of mind..I really enjoyed reading your blog. I really appreciate your information which you shared with us.
ReplyDeletesoftware testing course in chennai
https://www.zuaneducation.com/software-testing-training-course
Appreciation for really being thoughtful and also for deciding on certain marvelous guides most people really want to be aware of.
ReplyDeleteBlue Prism Training in Bangalore
ReplyDeleteNice post.Thank you so much for sharing.Yiioverflow is a web development company.We have well expert team in Angular JS, Ionic, Yii Framework, Node JS, Laravel, PHP, MySQL, and WordPress.If you want a developer visit.. https://yiioverflow.com/
Please let me know how to compose i cant find out xpath for that
ReplyDelete