如何使用Java中的Selenium Webdriver下载.docx文件? [英] How to download .docx file using Selenium webdriver in Java?

查看:121
本文介绍了如何使用Java中的Selenium Webdriver下载.docx文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以让我知道如何使用Selenium(java)下载Word文件吗?我的以下代码无法正常工作.

Can anyone let me know how to download a word file using selenium(java)? My below code is not working.

FirefoxProfile prof = new FirefoxProfile();
prof.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/word");

当我单击页面上的下载链接或图标"时,它会提示弹出窗口以保存下载文件(请参见下图),我需要单击弹出窗口中的OK按钮.

When I click on 'download link or icon' in the page, it prompts a popup to save the download file (see image below) and I need to click on OK button in the popup.

请告诉我如何使用Firefox.

Please let me know how to do this using Firefox.

推荐答案

您需要使用ROBOT类来引发ENTER Action事件.在Java中,如果您要触发任何事件,则必须使用Robot类以编程方式进行键入或触发ENTER和ESCAPE之类的事件.

You need to use ROBOT class for firing an ENTER Action event. In java if you want to fire any event you have to use Robot class for typing using programatically or firing events like ENTER and ESCAPE.

// Create object of Robot class
Robot object=new Robot();

// Press Enter
object.keyPress(KeyEvent.VK_ENTER);

// Release Enter
object.keyRelease(KeyEvent.VK_ENTER);

,有关此信息,您可以使用此链接

and for information regarding this you can use this link

这篇关于如何使用Java中的Selenium Webdriver下载.docx文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆