我已经使用代码上传文件。在这种情况下,我有文件上传身份证和收入照片。但不知何故上传文件没有2,selenium没有正确上传它。就像selenium一样,即使我的发现者(窗口)已经打开也不选择文件。
如果我禁用代码上传文件1,我上传文件2的代码也会出错
请查看以下代码: - 上传文件1(身份证)
//no 1
driver.findElement(By.id("uploadBtnOther_1")).click();
StringSelection ss = new StringSelection("/Users/prasetyo/Documents/Test/file upload/KTP-600x416.jpg");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
//native key strokes for CTRL, V and ENTER keys
Robot robot = null;
try {
robot = new Robot();
} catch (AWTException ex) {
Logger.getLogger(TestScripts.class.getName()).log(Level.SEVERE, null, ex);
}
robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_META);
robot.keyRelease(KeyEvent.VK_TAB);
robot.delay(500);
robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_G);
robot.keyRelease(KeyEvent.VK_META);
robot.keyRelease(KeyEvent.VK_SHIFT);
robot.keyRelease(KeyEvent.VK_G);
robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_META);
robot.keyRelease(KeyEvent.VK_V);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.delay(500);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ESCAPE);
Thread.sleep(3000);
上传文件2(收入照片)*无法上传
//上传GAJI driver.findElement(By.id(" uploadBtnOther_2&#34))。单击(); StringSelection gaji = new StringSelection(" / Users / prasetyo / Documents / Test / file upload / bug.jpg"); Toolkit.getDefaultToolkit()。getSystemClipboard()。setContents(gaji,null);
//native key strokes for CTRL, V and ENTER keys
try {
robot = new Robot();
} catch (AWTException ex) {
Logger.getLogger(TestScripts.class.getName()).log(Level.SEVERE, null, ex);
}
robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_META);
robot.keyRelease(KeyEvent.VK_TAB);
robot.delay(500);
robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_G);
robot.keyRelease(KeyEvent.VK_META);
robot.keyRelease(KeyEvent.VK_SHIFT);
robot.keyRelease(KeyEvent.VK_G);
robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_META);
robot.keyRelease(KeyEvent.VK_V);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.delay(500);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ESCAPE);
Thread.sleep(3000);
感谢专家