这是我的VBA代码,对此我是陌生的。几次我试图访问Tabheader菜单“投标”下的下拉菜单“我的投标”,但我做不到。我不知道该在哪里进行纠正...
Sub Test()
Dim IE As InternetExplorer
Dim doc As HTMLDocument
Dim ele As HTMLElementCollection
Set IE = New InternetExplorer
IE.Visible = True
IE.navigate "https://www.eprocure.gov.bd"
Do While IE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
Set doc = IE.document
doc.getElementById("txtEmailId").Value = "******"
doc.getElementById("txtPassword").Value = "******"
doc.getElementById("btnLogin").Click
For Each ele In doc.getElementByclassName("ddsubmenustyle")(0).getElementByTagName("a")
If InStr(ele.href, "/tenderer/MyTenders.jsp") > 0 Then doc.navigate ele.href: Exit For
Next ele
End Sub
这是我要获取访问权限的HTML代码。
<ul>
<li><a title="Home" href="/Index.jsp" id="headTabHomePage"><img alt="Home" src="/resources/images/Dashboard/HomeIcn.png">Home</a></li>
<li><a title="Message Box" href="/resources/common/InboxMessage.jsp" id="headTabMsgBox"><img alt="Message Box" src="/resources/images/Dashboard/msgBoxIcn.png">Message Box</a></li>
<li><a title="APP" href="#" rel="submenu-configuration" id="headTabApp" class=""><img alt="APP" src="/resources/images/Dashboard/AppIcn_1.png">APP</a></li>
<li><a title="Tender" href="#" rel="ddsubmenu2" id="headTabTender" **class="selected"><img alt="Tender" src="/resources/images/Dashboard/tenderIcn.png">Tender</a></li>
<li>**<a title="Doc. Library" href="#" rel="docMenu" id="headTabDocLib" class=""><img alt="Doc. Library" src="/resources/images/Dashboard/DocLib.gif">Doc. Library</a></li>
</ul>
<ul>
<li><a href="/tenderer/TenderWatchList.jsp">Watch List</a></li>
**<li><a href="/tenderer/MyTenders.jsp">My Tenders</a></li>**
<li><a href="/tenderer/RestrictedTenders.jsp">Limited Tenders</a></li>
<li><a href="/resources/common/AllTenders.jsp?h=f">All Tenders</a></li>
<li><a href="/tenderer/JvcaList.jsp">Propose JVCA</a></li>
</ul>
答案 0 :(得分:0)
代替此代码:
For Each ele In doc.getElementByclassName("ddsubmenustyle")(0).getElementByTagName("a")
If InStr(ele.href, "/tenderer/MyTenders.jsp") > 0 Then doc.navigate ele.href: Exit For
Next ele
您可以使用attribute = value css选择器(包含操作符,甚至以操作符结尾)替换这些行。
ie.document.querySelector("[href$='MyTenders.jsp']").click