Second file upload window not closing with selenium webdriver?

Here is the code I used to load the image through the upload window. The site has 5 download buttons, here I am trying to download two images from two view buttons. But my problem is, from the first window, the image is loaded and the window is closed, but from the second window, the image is loaded, a copy is copied, but the download window is not closed.

First window code:

     driver.findElement(By.xpath("//li[@id='upload_1']/input")).click();
         StringSelection ss = new StringSelection("D:\\cars\\audi.jpg");
         Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
            Robot robot = new Robot();
            robot.keyPress(KeyEvent.VK_ENTER);
             robot.keyRelease(KeyEvent.VK_ENTER);
            robot.keyPress(KeyEvent.VK_CONTROL);
             robot.keyPress(KeyEvent.VK_V);
             robot.keyRelease(KeyEvent.VK_V);
             robot.keyRelease(KeyEvent.VK_CONTROL);
             robot.keyPress(KeyEvent.VK_ENTER);
             robot.keyRelease(KeyEvent.VK_ENTER);

      

Second window code:

  driver.findElement(By.xpath("//li[@id='upload_2']/input")).click();   StringSelection ss1 = new StringSelection("C:\\Cars\\audiLights.jpg");
              Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss1, null);
          Robot robot1 = new Robot();
              robot1.keyPress(KeyEvent.VK_ENTER);
               robot1.keyRelease(KeyEvent.VK_ENTER);
              robot1.keyPress(KeyEvent.VK_CONTROL);
               robot1.keyPress(KeyEvent.VK_V);
               robot1.keyRelease(KeyEvent.VK_V);
               robot1.keyRelease(KeyEvent.VK_CONTROL);
               robot1.keyPress(KeyEvent.VK_ENTER);
               robot1.keyRelease(KeyEvent.VK_ENTER);

      

+3


source to share


1 answer


The "Browse" / "Boot window" window is closed by adding a sleep mode 3-4 seconds before the "Enter last press" key is pressed. Thanks Subh for all this :)



+4


source







All Articles