Reputation: 532
Here is the code those i used to uploading image via uploading window. On the site there are 5 uploading button, here i try to upload two images from two browse buttons. But my problem is that, from first window image is upload and window closed, but from the second uploading window image url is copied but uploading window does not close.
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);
Upvotes: 4
Views: 188
Reputation: 532
Yes Browse window/Uploading window is closing by adding sleep of 3-4 second before the Last Enter Key Pressed. Thank to Subh for this all:)
Upvotes: 5