Vba 如何获取内部元素<;表格>;网页标签?

Vba 如何获取内部元素<;表格>;网页标签?,vba,excel,Vba,Excel,我想访问网站“表单”标签中的按钮,如果我打印表单的内部文本,我可以获得整个页面,但我不知道如何访问表单中的元素 已尝试的代码: Dim workFrame As HTMLFormElement, test As HTMLFormElement Dim HTMLDoc As HTMLDocument Set workFrame = ie2.Document.forms("ViewReferral") Debug.Print workFrame.innerText ' it will print t

我想访问网站“表单”标签中的按钮,如果我打印表单的内部文本,我可以获得整个页面,但我不知道如何访问表单中的元素

已尝试的代码:

Dim workFrame As HTMLFormElement, test As HTMLFormElement
Dim HTMLDoc As HTMLDocument
Set workFrame = ie2.Document.forms("ViewReferral")
Debug.Print workFrame.innerText ' it will print the whole page
Debug.Print workFrame.elements("notsuccess").innerText ' this triggered an error
网页

<form name="ViewReferral" action="viewreferral.php" method="POST">
<input name="Id" id="Id" type="hidden" value="11111">
<input name="Message" id="Message" type="hidden" value="">
 <div id="data-form" style="padding: 10px;">

    <div style="padding: 10px; float: left;"><h1>View Referral (Id = 11111)</h1></div>

        <div class="order">
            <a class="ui-button ui-corner-all ui-widget"role="button" style="float: right; display: inline;" href="managedocuments.php">Back</a>
            <a class="ui-button ui-corner-all ui-widget" role="button" style="float: right; display: inline;" href="vieworder.pdf.php?OrderId=111111" target="_blank">Print</a>
                <a class="VoidOrder ui-button ui-corner-all ui-widget" role="button" style="float: right; display: inline;" href="#1111"> Void</a>
                        <a class="ui-button ui-corner-all ui-widget" role="button" style="float: right; display: inline;" href="markasprocessed.php?OrderId=11111">Mark as Processed</a>

视图引用(Id=11111)
我想在这里激活href=“vieworder.pdf.php”
我无法访问web表单中的表,请帮助我解决此问题。

谢谢。

将我的评论形式化,您应该尝试使用
GetElementsByCassName
,它返回文档或表单中具有给定类的每个元素的数组。在您的情况下,因为您要使用的
标记是具有类
“ui按钮ui角落所有ui小部件的第二个标记“
,并且在
工作框架
表单中,应该适用于您的代码行是:

workFrame.getElementsByClassName("ui-button ui-corner-all ui-widget") (1)

其中(1)告诉程序返回数组中的第二项(数组从0开始索引)。

注释中给出了一个漂亮的CSS选择器,带有

.Document.querySelector("a[href*='markasprocessed.php']")
*
表示包含。因此,
a
标记有一个
href
包含文本字符串
'markasprocessed.php


^
表示以开头。因此,
a
标记有一个
href
以文本字符串
'markasprocessed.php


您还可以使用不太健壮的基于位置的选择器:

.Document.querySelector("a[href]:nth-child(4)")


第四个
a
标记包含
href.

这可能会引导您尝试使用
workFrame.getElementsByClassName(“ui按钮ui角落所有ui小部件”)(1)
。单击
.innerText
或任何您希望与标记一起使用的方法。调用
ie2.Document.querySelector(“a”)[href*='markasprocessed.php']”
来获取按钮。@Nicholas Kemp非常感谢,它工作得很好,你救了我…继续帮助..谢谢你,一个小疑问是我应该如何为这些元素分配一个对象?我使用Dim test作为对象,并设置test=workFrame.getElementsByClassName(“ui按钮ui角落所有ui小部件”)(1),它给我带来了一个错误,我也尝试过使用Dim test作为HTMLFormElement的测试,但它仍然会引发一个错误,我不知道怎么做,但你到底想用它实现什么?也许还有另一种方法。
.Document.querySelector("a[href]:nth-child(4)")