VBA 在 Internet Explorer 上
VBA on Internet Explorer
我正在尝试使用 VBA 和 Internet Explorer 使 Intranet 网站中的流程自动化。
首先要做的是单击 "button" 访问内联网中的另一个屏幕,但我已经尝试了很多方法来做到这一点,但没有成功。你能帮我学习如何点击这个按钮吗?
我已经尝试过使用 querySelector 的方式并尝试搜索样式,说明跨度,但我有更多 "buttons" 具有相同的样式,但这是行不通的。
上述两种方式的代码都可以编译,但是在 IE 屏幕上,不会发生...
<span style="font-weight: normal; font-family: Arial; font-size: 9pt;
font style: normal; text-decoration: none;">Invoiced<img alt=""
src="/QvAjaxZfc/QvsViewClient.aspx?datamode=binary&name=LED&host=QVS%40cbrcur01apcp480&slot=&public=only&color=%2300f010&xrfkey=nEDfFknqkhWgtMq9"
class="icon" style="height: 10px; width: 10px;">
</span>
还有一个Javascript也是可以点击的,代码如下:
<li id="Document\SH05" rel="DocumentSH05" order="1" style="display: list-item;"> <a href="javascript:;"
style="color: rgb(255, 255, 255); background: rgb(175, 40, 63);">
<span style="font-weight: normal; font-family: Arial; font- size: 9pt; font-style: normal; text-decoration: none;">
Invoiced<img alt="" src="/QvAjaxZfc/QvsViewClient.aspx?datamode=binary&name=LED&host=QVS%40cbrcur01apcp480&
slot=&public=only&
color=%2300f010&xrfkey=nEDfFknqkhWgtMq9" class="icon" style="height: 10px; width: 10px;"></span></a></li>
我需要点击按钮,但是现在,我没有任何结果。
我当前的代码是:
Sub demo()
Dim IE As InternetExplorerMedium
Dim html As HTMLDocument
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate2 "Example"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
'IE.document.getElementById("Document\SH08").Click
Set valores = IE.document.getElementsByTagName("li")
For Each valor In valores
If valor.getAttribute("id") = "Document\SH05" Then
valor.Click
Exit For
End If
Next valor
结束子
尝试参考下面的示例可能会解决您的问题。
Sub demo()
Dim IE As InternetExplorer
Dim html As HTMLDocument
Set IE = New InternetExplorerMedium
IE.Visible = True
IE.Navigate2 "D:\Backup20190913\tests5.html"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Dim objTag As Object
For Each objTag In IE.document.getElementsByTagName("span")
If InStr(objTag.outerHTML, "Invoiced") > 0 Then
objTag.Click
Exit For
End If
Next
Stop
IE.Quit
Set IE = Nothing
End Sub
可以点击你的span标签。
输出:
我找到了解决办法。我确实为 VBA 安装了 Selenium 库并为 Chrome 更改了 InternetExplorer。
现在,我用 Xpatch 单击相应的 link(driver.FindElementByXPath("XPATCH")。单击)。
工作得非常棒!
谢谢!!
我正在尝试使用 VBA 和 Internet Explorer 使 Intranet 网站中的流程自动化。
首先要做的是单击 "button" 访问内联网中的另一个屏幕,但我已经尝试了很多方法来做到这一点,但没有成功。你能帮我学习如何点击这个按钮吗?
我已经尝试过使用 querySelector 的方式并尝试搜索样式,说明跨度,但我有更多 "buttons" 具有相同的样式,但这是行不通的。
上述两种方式的代码都可以编译,但是在 IE 屏幕上,不会发生...
<span style="font-weight: normal; font-family: Arial; font-size: 9pt;
font style: normal; text-decoration: none;">Invoiced<img alt=""
src="/QvAjaxZfc/QvsViewClient.aspx?datamode=binary&name=LED&host=QVS%40cbrcur01apcp480&slot=&public=only&color=%2300f010&xrfkey=nEDfFknqkhWgtMq9"
class="icon" style="height: 10px; width: 10px;">
</span>
还有一个Javascript也是可以点击的,代码如下:
<li id="Document\SH05" rel="DocumentSH05" order="1" style="display: list-item;"> <a href="javascript:;"
style="color: rgb(255, 255, 255); background: rgb(175, 40, 63);">
<span style="font-weight: normal; font-family: Arial; font- size: 9pt; font-style: normal; text-decoration: none;">
Invoiced<img alt="" src="/QvAjaxZfc/QvsViewClient.aspx?datamode=binary&name=LED&host=QVS%40cbrcur01apcp480&
slot=&public=only&
color=%2300f010&xrfkey=nEDfFknqkhWgtMq9" class="icon" style="height: 10px; width: 10px;"></span></a></li>
我需要点击按钮,但是现在,我没有任何结果。
我当前的代码是:
Sub demo()
Dim IE As InternetExplorerMedium
Dim html As HTMLDocument
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate2 "Example"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
'IE.document.getElementById("Document\SH08").Click
Set valores = IE.document.getElementsByTagName("li")
For Each valor In valores
If valor.getAttribute("id") = "Document\SH05" Then
valor.Click
Exit For
End If
Next valor
结束子
尝试参考下面的示例可能会解决您的问题。
Sub demo()
Dim IE As InternetExplorer
Dim html As HTMLDocument
Set IE = New InternetExplorerMedium
IE.Visible = True
IE.Navigate2 "D:\Backup20190913\tests5.html"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Dim objTag As Object
For Each objTag In IE.document.getElementsByTagName("span")
If InStr(objTag.outerHTML, "Invoiced") > 0 Then
objTag.Click
Exit For
End If
Next
Stop
IE.Quit
Set IE = Nothing
End Sub
可以点击你的span标签。
输出:
我找到了解决办法。我确实为 VBA 安装了 Selenium 库并为 Chrome 更改了 InternetExplorer。
现在,我用 Xpatch 单击相应的 link(driver.FindElementByXPath("XPATCH")。单击)。
工作得非常棒!
谢谢!!