Java 使用robot浏览文件-有时浏览错误的文件
我需要从我的电脑浏览一个文件到网络 我使用机器人的方法Java 使用robot浏览文件-有时浏览错误的文件,java,selenium,Java,Selenium,我需要从我的电脑浏览一个文件到网络 我使用机器人的方法 browseButton.click(); test.log(LogStatus.PASS, "Buttom is clicked"); setClipboardData**("C:\\SLT file\\small.stl**"); Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.ke
browseButton.click();
test.log(LogStatus.PASS, "Buttom is clicked");
setClipboardData**("C:\\SLT file\\small.stl**");
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
public void setClipboardData(String string)
{
StringSelection stringSelection = new StringSelection(string);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
}
有时工作正常,有时显示消息:
你知道为什么会这样吗?只需在浏览器中以以下方式打开此文件:
@Test
public void shouldOpenLocalFileInABrowser() throws InterruptedException {
WebDriver driver = new ChromeDriver();
driver.get("file:///C:/tmp/ala.csv");
Thread.sleep(5000);
driver.quit();
}
这是上述代码的结果:
只需在浏览器中以以下方式打开此文件:
@Test
public void shouldOpenLocalFileInABrowser() throws InterruptedException {
WebDriver driver = new ChromeDriver();
driver.get("file:///C:/tmp/ala.csv");
Thread.sleep(5000);
driver.quit();
}
这是上述代码的结果:
它什么时候运行良好?它似乎看到了文件名
v
,这意味着它没有获得控制键。你的机器人比人类跑得快得多。您可能应该引入一些延迟。它什么时候运行良好?它看起来像是看到了文件名v
,这意味着它没有获得控制键。你的机器人比人类跑得快得多。你可能应该引入一些延迟。