上传时更改Selenium中的文件目录[已关闭]

bwntbbo3  于 2022-11-24  发布在  其他
关注(0)|答案(1)|浏览(179)

已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题吗?**通过editing this post添加详细信息并阐明问题。

9天前关闭。
Improve this question
我需要执行windows操作来上传文件。你能给我一些建议吗
哪一个更好Auto it还是sikuli

8cdiaqws

8cdiaqws1#

我认为使用机器人框架比自动化更方便

//open the upload window from upload option
     driver.findElement(By.id("yourID")).click();

     //add your upload file path including filename and extension
     StringSelection ss = new StringSelection("C://Users//zsbappa//Desktop//myfile.csv");
     Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);

     //imitate mouse events like ENTER, CTRL+C, CTRL+V We are just paste file name in the path using mouse event

     Robot robot = new Robot();
     robot.delay(250);
     robot.keyPress(KeyEvent.VK_ENTER);
     robot.keyRelease(KeyEvent.VK_ENTER);
     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.delay(90);
     robot.keyRelease(KeyEvent.VK_ENTER);

相关问题