Im trying to upload a file from my projects root folder using Robot Framework and Java. When the popup window opens, the root file path is sent to popup but the popup never closes to submit the file. If i change the file path to the desktop the popup opens the desktop file path is submitted and popup closes submitting the file.
Heres my Robot class
package utils;
import static java.awt.event.KeyEvent.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class RobotWrite {
private Robot robot;
public RobotWrite() throws AWTException {
this.robot = new Robot();
}
public void type(CharSequence characters) throws AWTException {
int length = characters.length();
for (int i = 0; i < length; i++) {
char character = characters.charAt(i);
type(character);
}
}
public void type(char character) throws AWTException {
switch (character) {
case 'a': doType(VK_A); break;
case 'b': doType(VK_B); break;
.........
.........
case '?': doType(VK_SHIFT, VK_SLASH); break;
case ' ': doType(VK_SPACE); break;
default:
throw new IllegalArgumentException("Cannot type character " + character);
}
}
private void doType(int... keyCodes) {
doType(keyCodes, 0, keyCodes.length);
}
private void doType(int[] keyCodes, int offset, int length) {
if (length == 0) {
return;
}
robot.keyPress(keyCodes[offset]);
doType(keyCodes, offset + 1, length - 1);
robot.keyRelease(keyCodes[offset]);
}
}
And my calling method where i set the path..
public static void Robotwrite() throws Exception{
try{
RobotWrite rw = new RobotWrite();
rw.type("C:\\workspace\\project\\src\\main\\resources\\data\\ExampleCV.docx"); //doesnt work
//rw.type("C:\\Users\\Desktop\\ExampleCV.docx"); //works
Robot r = new Robot();
r.keyPress(VK_ENTER);
r.keyRelease(VK_ENTER);
}catch (Exception e){
Log.error("Could not write");
throw(e);
}
}