title: How to upload multiple files using Robot class in selenium Webdriver (Mac)?
body: <p>I am trying to upload a file in selenium webdriver using Robot class and i am using Mac machine. Send keys doesnt work. Below is the code and it works fine when i load a file first time. I am trying to upload another file from the same page again but since the applet is open, no file is getting selected and script fails</p>
  
  <pre><code>browse.click(); // Click on a browse button from the page
  File file = new File(photoLocation); //send path of the file
  
  StringSelection StringSelection = new StringSelection(file.getAbsolutePath());
  
  Toolkit.getDefaultToolkit().getSystemClipboard().setContents(StringSelection, null); //Copies the filepath to clipboard
  
  
  robot = new Robot();
  
  //This launches java applet, so we are using cmd+tab to shift the focus
      robot.keyPress(KeyEvent.VK_META);
      robot.keyPress(KeyEvent.VK_TAB);
      robot.keyRelease(KeyEvent.VK_META);
      robot.keyRelease(KeyEvent.VK_TAB);
      robot.delay(500);
  
  //Open Goto window
      robot.keyPress(KeyEvent.VK_META);
      robot.keyPress(KeyEvent.VK_SHIFT);
      robot.keyPress(KeyEvent.VK_G);
      robot.keyRelease(KeyEvent.VK_META);
      robot.keyRelease(KeyEvent.VK_SHIFT);
      robot.keyRelease(KeyEvent.VK_G);
  
  //Paste the clipboard value
      robot.keyPress(KeyEvent.VK_META);
      robot.keyPress(KeyEvent.VK_V);
      robot.keyRelease(KeyEvent.VK_META);
      robot.keyRelease(KeyEvent.VK_V);
  
  //Press Enter key to close the Goto window and Upload window
      robot.keyPress(KeyEvent.VK_ENTER);
      robot.keyRelease(KeyEvent.VK_ENTER);
      robot.delay(500);
      robot.keyPress(KeyEvent.VK_ENTER);
      robot.keyRelease(KeyEvent.VK_ENTER);
  </code></pre>
  
  <p>i am using the same code to be called again from the main page to upload the second file. But since the java applet is still open, i am unable to upload the file. Is there a way for me to close the applet?</p>