You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac环境下无input标签时Selenium Java上传CSV文件失败求助

上传CSV文件的自动化问题

点击上传按钮后会打开桌面应用窗口以选择CSV文件,但页面中没有file类型的input标签,导致Send Keys方法无法生效,Robot类也无法正常工作。

上传按钮界面
文件选择窗口

我尝试了Send Keys和Robot类两种方法,但都没能解决问题,希望能得到帮助。

我使用的Robot类代码如下:

StringSelection stringSelection= new StringSelection(file.getAbsolutePath());
//Copy to clipboard 
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
browserDriver.waitTime(MainConfig.timeout_for_AJAX);
Robot robot = new Robot();

// Cmd + Tab is needed since it launches a Java app and the browser looses focus
robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_TAB);
robot.delay(1000);
robot.keyRelease(KeyEvent.VK_META);
robot.keyRelease(KeyEvent.VK_TAB);
robot.delay(1000);

//Open Goto window
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);

//Paste the clipboard value
robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_META);
robot.keyRelease(KeyEvent.VK_V);

//Press Enter key to close the Goto window and Upload window
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);

内容的提问来源于stack exchange,提问作者Viraj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 12:01:01