Question

I am using this code to uploading file via window prompt in selenium webdriver . it passes the test but didn't upload the file:

StringSelection abc= new StringSelection("E:\\Study Materials\\Resume And Cv\\Sample 1_0.doc");
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(abc, 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);
Was it helpful?

Solution

Can u try the following selenium way instead of using Robot class.

WebElement UploadElem = driver.findElement(By.id("#Upload element id"));
UploadElem.sendKeys("PATH FOR FILE");
driver.findElement(By.id("#Submit button ID")).click();

Hope this works...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top