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

查看:33
本文介绍了如何在 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天全站免登陆