Handling Export and Import by using Keys.
WebElement link = driver.findElement(By.xpath("myxpath"));
ExportAndSaveFileInIE(link, Path);
public static void ExportSaveFileInIE(WebElement element,String sFilepath) throws
InterruptedException{
try {
Robot robot = new Robot();
//Focus the Element
element.sendKeys("");
//Press Enter Key to populate Window
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
//Wait For Dialog
Thread.sleep(2000);
//press s key to save
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_S);
Thread.sleep(2000);
//press enter to save the file with specified name and in location
sFilepath = sFilepath.ToUpperCase()
for (int i=0;i<=sFilepath .length();i++)
{
Char ch = sFilepath.ChartAt(i);
int iascvalue = ch;
switch(ch)
{
Case ":"
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_COLON);
robot.keyRelease(KeyEvent.VK_COLON);
robot.keyRelease(KeyEvent.VK_SHIFT);
Case "\"
....
default
robot.keyPress(iascvalue );
robot.keyRelease(iascvalue );
}
}
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException e) {
e.printStackTrace();
}
No comments:
Post a Comment