How to download .docx file using Selenium webdriver in Java?(如何在 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 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Java 中使用 Selenium webdriver 下载 .docx 文件?
基础教程推荐
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 如何对 Java Hashmap 中的值求和 2022-01-01
