如何在 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
相关文章