Earn Money in 10 days

Selenium Videos

Protractor In Selenium

Livechat

Showing posts with label How to send a file in gmail using selenium. Show all posts
Showing posts with label How to send a file in gmail using selenium. Show all posts

Wednesday, 25 February 2015

How to send a attachment via gmail using Selenium(Using Robot Class)

Scenario:

Open gmail.com
Enter 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
   }
}

Popular Posts

 
subscribe
Subscribe Us
emailSubscribe to our mailing list to get the updates to your email inbox... We can't wait more to have your email in our subscribers email list. Just put your nice email in below box: