我尝试使用Robot Framework和Java从我的项目根文件夹上传文件。弹出窗口打开时,根文件路径将被发送到弹出窗口,但弹出窗口永远不会关闭以提交文件。如果我将文件路径更改为桌面,弹出窗口将提交桌面文件路径,弹出窗口将关闭提交文件。
继承我的机器人课程
<!DOCTYPE html>
<html>
<head>
<title>Learning Angular</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script type="text/javascript" src="LearningAngular.js"></script>
</head>
<body ng-app="myApp" ng-controller="myController">
First Name: <input type="text" ng-model="firstName"><br>
<br>
Full Name: {{firstName}}<br>
<button onclick="start_counting()">Start Counting</button><br>
Counter: <span>{{counter}}</span>
</body>
</html>
我的调用方法,我设置路径..
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]);
}
}
答案 0 :(得分:-1)
通常,您可以通过将文件路径发送到网站的输入元素(例如上传按钮)来解决此问题。