Monday, 16 May 2016

Working on window based popups using robot keys with Selenium

package interview;

import java.awt.AWTException;
import java.awt.Robot;
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.openqa.selenium.firefox.FirefoxProfile;

public class Window_Popups_Handling {

    /**
     * @param args
     * @throws AWTException
     * @throws InterruptedException
     */
    public static void main(String[] args) throws AWTException, InterruptedException {
        // TODO Auto-generated method stub

        WebDriver driver=new FirefoxDriver();
               
        driver.get("http://seleniumhq.org/download/");
        driver.manage().timeouts().implicitlyWait(9000,TimeUnit.SECONDS);
        driver.findElement(By.xpath("html/body/div[1]/div[2]/div[2]/p[6]/a")).click();
        System.out.println("hiiii");
        Robot robot=new Robot();
        Thread.sleep(2000);
          robot.keyPress(KeyEvent.VK_ALT);
          robot.keyPress(KeyEvent.VK_S);
          robot.keyRelease(KeyEvent.VK_S);
           robot.keyRelease(KeyEvent.VK_ALT);
           robot.keyPress(KeyEvent.VK_ENTER);
           System.out.println("File is downloaded");

       
       
       
        //driver.close();
   
    }
   

}

No comments:

Post a Comment