I came across this situation I have a file upload scenario ..here i can not use the sendKeys approach to send the absolute path of the file as there is no input element ,i have only a 'browse' button to select the file from the local folder
so to handle this i use the robot class and the below logic after clicking the 'browser' button using selenium webdriver:
StringSelection sc = new StringSelection(file); >>file is the one to upload
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sc, null);
try {
Robot robot= new Robot();
robot.delay(3000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.delay(2000);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.delay(3000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}
This works very well in chrome and in firefox...but not in Internet Explorer 11 In IE the model dialogue opens ,but it is not pasting the path of the file which is suppose to be uploaded Is any one facing this issue in IE Do we have to do anything extra to do this in IE Please let me know
Thanks, Musaffir
Determines whether to require that the IE window have focus before performing any user interaction operations (mouse or keyboard events). This capability is false by default, but delivers much more accurate native events interactions.
Set Capabilty type like below.it's working for me.
capabilities.setCapability("requireWindowFocus", false);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.