Earn Money in 10 days

Selenium Videos

Protractor In Selenium

Livechat

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
   }
}

19 comments:

  1. What is ROBOt Class? Can you please explain

    ReplyDelete
  2. http://www.seleniumgyan.com/2014/11/how-to-upload-file-in-selenium.html

    ReplyDelete
  3. C:\\Users\\Ritika Gulati\\Downloads\\Asp.doc this path is not taken by selenium shopowing error

    ReplyDelete
    Replies
    1. i should only enter name of file : asp.doc which should be in desktop.
      it's working

      Delete
  4. 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.
    ways to consult gmail

    ReplyDelete
  5. Thanks a lot . Working fine. :)

    ReplyDelete
  6. Gmail 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

    ReplyDelete
  7. how you generate attachment icon xpath.

    ReplyDelete
  8. really 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.
    selenium training in chennai

    ReplyDelete
  9. 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.
    android training in chennai

    ReplyDelete
  10. useful 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

    ReplyDelete
  11. Hats off to your presence of mind..I really enjoyed reading your blog. I really appreciate your information which you shared with us.

    software testing course in chennai

    https://www.zuaneducation.com/software-testing-training-course

    ReplyDelete
  12. Appreciation for really being thoughtful and also for deciding on certain marvelous guides most people really want to be aware of.
    Blue Prism Training in Bangalore

    ReplyDelete

  13. Nice 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/

    ReplyDelete
  14. Please let me know how to compose i cant find out xpath for that

    ReplyDelete

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: