how to get elements inside <form> tag of web

2020-03-05 02:39发布

I would like to access a button which is present inside "form" tag of website, if i print the inner text of form i can able to get the entire page but i don't know how to access the elements inside the form.

Code tried:

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

Web Page

<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>

Here i would like to activate href="vieworder.pdf.php?
I am unable to access the tables inside the web form, please help me to fix this issue.
Thank You.

2条回答
对你真心纯属浪费
2楼-- · 2020-03-05 03:20

Formalizing my comment, what you should try is using getElementsByClassName, which returns an array of every element in the document or form with a given class. In your case, since the <a> tag you want to work with is the second tag with the class "ui-button ui-corner-all ui-widget", and is in the workFrame form, the code line that should work for you is:

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

where the (1) tells the program to return the second item in the array (arrays start indexing from 0).

查看更多
来,给爷笑一个
3楼-- · 2020-03-05 03:24

A nice CSS selector was given in the comments with

.Document.querySelector("a[href*='markasprocessed.php']")

The * means containing. So the a tag that has an href containing the literal string 'markasprocessed.php


Or

.Document.querySelector("a[href^='markasprocessed.php']")

The ^ means starts with. So the a tag that has an href starting with the literal string 'markasprocessed.php

css query 1


You could also use a less robust positional based selector with:

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

CSS selector

The 4th a tag containing an href.

查看更多
登录 后发表回答