Monday, January 13, 2014

File Upload

            WebDriver driver=new FirefoxDriver();
            driver.get("http://www.google.com/");
            driver.findElement(By.id("upField")).sendKeys("c:\\usres\\lab\\desktop\\hemu.jpg");

Downloading a file using selenium webdriver

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_ALT);
FirefoxProfile prof=new FirefoxProfile()
prof.setPreference("browser.downLoad.folderList", 2);
prof.setPreference("browser.helperApps.neverAsk.saveToDisk", "Applications/zip");