首页 > 解决方案 > 如何使用 VBA 在 Internet Exlorer 中单击 SPAN 元素

问题描述

我试图点击我使用用户名和密码访问的网站上的 span 元素,我尝试了所有可能的方法(大部分都在这个网站上找到)。也许你可以帮助我,这是我正在使用的代码:

Sub internet_explore()

Dim ie As InternetExplorer
Dim page As HTMLDocument


Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
ie.Navigate2 "TheWebPage"

Do While ie.readyState <> READYSTATE_COMPLETE 
DoEvents
Loop

'Here I enter code to do the login and make a search  by filling an input box and  clicking on search button

'wait for the search to load up
Do While ie.readyState <> READYSTATE_COMPLETE
DoEvents
Loop

Set page = ie.Document

Dim e as HTMLElementCollection
Dim c As HTMLButtonElement

For Each e In page.getElementsByTagName("span")
    If e.innerText = "10.180.9.1" Then  

      Set c = e
      c.click
      c.parentElement.click

   End If

Next

End Sub

这是我搜索的内容和我单击的按钮: 我搜索的内容

我得到的结果(表)以及为什么我需要单击该跨度元素,因为我得到了很多结果: 结果

<div class="x-grid3-cell-inner x-grid3-col-column7" style="CURSOR: pointer" unselectable="on">
<span class="Grid-Panel-All">10.180.9.1<div>

标签: htmlexcelvba

解决方案


推荐阅读