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 文件?
基础教程推荐
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- JPA惰性列表上的流 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
