简体   繁体   English

从Java中的HTML文件下载Excel文件

[英]Download an excel file from an html file in java

I'm using Webdriver to perform all the UI actions. 我正在使用Webdriver执行所有UI操作。 I want to download an excel file on Click operation of a WebElement. 我想在WebElement的Click操作上下载一个excel文件。 The below is the html code of the application. 以下是应用程序的html代码。

<span class="excel ExcelLink" onclick="document.expForm.submit();">Download Excel</span>

I'm getting error has this WebElement doesn't have any 'href' attribute present in this. 如果此WebElement中没有任何“ href”属性,则会出现错误。 Hence I can't use the "HttpClient" to retrieve the file. 因此,我无法使用“ HttpClient”来检索文件。 how to download in this file in java / javascript? 如何在java / javascript中的此文件中下载?

Kindly suggest. 请提示。

can u post full link to website? 您可以发布网站的完整链接吗? I think you are getting into this from wrong way. 我认为您是从错误的方式进入这一过程的。 See that this element isnt anchor with href button but i suppose its form that redirects U to the file ( maybe file isn't on server just generated for download and than destroyed?). 看到这个元素不是带有href按钮的锚点,但是我想它的形式会将U重定向到文件(也许文件不是在服务器上生成的,而是为了下载而被破坏的?)。 Have U tried executing onclick function?? 您是否尝试过执行onclick函数?

 <button onclick="myFunction()">Click me</button>

@Luke Park, sorry for that, but i cant make only comments yet. @卢克·帕克(Luke Park),对不起,但是我还不能发表评论。 I have to earn 50 points. 我必须赚取50分。 Sorry if U not welcome with that. 对不起,如果您不对此表示欢迎。 Here u have some code. 在这里,您有一些代码。

Python way: downloading file using selenium Python方式: 使用Selenium下载文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM