I cannot simulate a click event on a div element. The HTML code is this one:
我无法模拟div元素上的click事件。 HTML代码是这样的:
<div id="export" data-export="true" data-timespan="">
<button class="btn btn-default ladda-button" type="button" data-style="expand-right" data-spinner-color="#8899a6">
<span class="Icon Icon--featherDownload"></span>
<span class="ladda-label">
Exportar datos
</span>
<span class="ladda-spinner"></span></button>
<div class="hidden error server Callout Callout--danger">
<p>Ocurrió un problema al exportar tus datos, inténtalo de nuevo más tarde.</p>
</div>
</div>
In the webpage, is just a button that downloads a file when clicked. There is no URL. But after checking the code, is the div element what triggers the click event. Look the image.
在网页中,只是一个单击时下载文件的按钮。没有网址。但是在检查代码之后,div元素是什么触发了click事件。看图像。
点击查看图片
That "g.handle" triggers a js.file form the website.
那个“g.handle”触发了一个js.file形式的网站。
My vba code works perfect for doing other stuff in the website, but I cannot accomplish this task.
我的vba代码非常适合在网站上做其他事情,但我无法完成这项任务。
I've tried all this options:
我尝试了所有这些选项:
Set div = HTMLDoc.getElementById("export")
div.FireEvent ("onclick")
div.Click
HTMLDoc.all.Item
Call HTMLDoc.parentWindow.execScript("g.handle", "JavaScript")
Nothing works. I'm kind of blocked right now and I have no idea of how to proceed. Maybe this has no solution? I have almost no idea of HTML and I have 0 idea of Javascript. But it must have a solution, because if I do it manually, i click on that DIV, wait some seconds and download my file.
什么都行不通。我现在被*了,我不知道该怎么办。也许这没有解决方案?我几乎不知道HTML,我对Javascript有一点想法。但它必须有一个解决方案,因为如果我手动执行,我点击该DIV,等待几秒钟并下载我的文件。
Thanks in advance. Any help is welcome.
提前致谢。欢迎任何帮助。
1 个解决方案
#1
2
You didn't specify if the highlighted portion was the html code for the button or not, but it appears from looking at it that it isn't.
你没有指定突出显示的部分是否是按钮的html代码,但是看起来它不是。
You can grab the class name for your button. The name may or may not be unique, and it's difficult to know that without seeing the entire html code, but you can set the btn
variable below to the first instance of that class name. If there are multiple class names in your html code, then you will need to use a For Each...Next
statement to iterate through them (unless you know the instance number off hand).
您可以获取按钮的类名称。该名称可能是唯一的,也可能不是唯一的,并且很难知道如果没有看到整个html代码,但您可以将下面的btn变量设置为该类名的第一个实例。如果你的html代码中有多个类名,那么你需要使用For Each ... Next语句来迭代它们(除非你知道实例编号)。
So we will go with the first instance of your class, hence the reason for the (0)
appended on the end.
因此,我们将使用您的类的第一个实例,因此最后附加(0)的原因。
Sub Test()
Dim ie As New InternetExplorer, HTMLDoc As HTMLDocument, btn As Object
ie.navigate Url 'whatever this may be
' Some code to wait for your page to fully load
Set HTMLDoc = ie.document
Set btn = HTMLDoc.getElementsByClassName("btn btn-default ladda-button")(0)
btn.Click
End Sub
#1
2
You didn't specify if the highlighted portion was the html code for the button or not, but it appears from looking at it that it isn't.
你没有指定突出显示的部分是否是按钮的html代码,但是看起来它不是。
You can grab the class name for your button. The name may or may not be unique, and it's difficult to know that without seeing the entire html code, but you can set the btn
variable below to the first instance of that class name. If there are multiple class names in your html code, then you will need to use a For Each...Next
statement to iterate through them (unless you know the instance number off hand).
您可以获取按钮的类名称。该名称可能是唯一的,也可能不是唯一的,并且很难知道如果没有看到整个html代码,但您可以将下面的btn变量设置为该类名的第一个实例。如果你的html代码中有多个类名,那么你需要使用For Each ... Next语句来迭代它们(除非你知道实例编号)。
So we will go with the first instance of your class, hence the reason for the (0)
appended on the end.
因此,我们将使用您的类的第一个实例,因此最后附加(0)的原因。
Sub Test()
Dim ie As New InternetExplorer, HTMLDoc As HTMLDocument, btn As Object
ie.navigate Url 'whatever this may be
' Some code to wait for your page to fully load
Set HTMLDoc = ie.document
Set btn = HTMLDoc.getElementsByClassName("btn btn-default ladda-button")(0)
btn.Click
End Sub