我们正在进行自动化测试,并且遇到了需要从浏览器下载文件的情况。 在下载时,当下载按钮被击中时,我们将进入系统弹出窗口进行下载,我们需要执行输入操作。KeyPress Enter for Selenium
有人可以帮助我们如何执行输入或键盘操作,目前我们正在使用机器人API,但它不是在网格系统上工作, 这是我的机器人代码可以增强和使用,或我们有任何另一种方式做到这一点
** * ** * **代码* ** * ** * ** * ***
public void downloadReportFromMyExport(WebDriver driver, String downloadSufixId) throws AWTException,
InterruptedException
{
String downloadPrefixId = ConfigProperty.getConfig("downloadPrefixId").trim();
String[] suffix;
suffix = StringUtil.split(downloadSufixId, "TR_EXP_");
String suffixPart = suffix[0];
String completeId = downloadPrefixId.concat(suffixPart);
By id = By.id(completeId);
WebElement element = driver.findElement(id);
element.click();
Robot pressKey = new Robot();
pressKey.keyPress(KeyEvent.VK_ENTER);
pressKey.keyRelease(KeyEvent.VK_ENTER);
threadSleep("5");
pressKey.keyPress(KeyEvent.VK_ALT);
pressKey.keyPress(KeyEvent.VK_F4);
pressKey.keyRelease(KeyEvent.VK_F4);
pressKey.keyRelease(KeyEvent.VK_ALT);
logger.info("Downlaod Complete");
}
上述代码在网格设置上运行自动化时不工作 –