【问题标题】:VBA to click through hover dropdown menusVBA单击悬停下拉菜单
【发布时间】:2014-11-19 22:12:19
【问题描述】:

我有一个类似于this question here 的请求,我刚刚找到并正在调查this request here as well。我正在尝试构建一个 VBA 宏来抓取一些 Web 数据,并且我已经通过了登录屏幕,但现在我被卡住了,因为该页面似乎是用 javascript 编写的,而且我完全不熟悉如何使用它。我对 HTML 很模糊,并且一直在自学。下面是我到目前为止的 VBA,取消的代码行显示了我尝试过的不起作用的内容。我要做的是单击“报告”的链接,该链接位于由 onmouseover 激活的名为“我的 Sequentra”的下拉菜单下。感谢您的帮助。

Sub SingleSiteReportPull()

Dim ie As Object
Dim form As Variant, button As Variant

Set ie = CreateObject("InternetExplorer.Application")

'''''Set input boxes for username, password, & site to pull report for'''''
myusername = InputBox("Enter Your Sequentra Username")
mypassword = InputBox("Enter Your Sequentra Password")
searchsite = InputBox("Which site would you like to pull a report for?")

'''''Go to webpage'''''
With ie
.Visible = True
.navigate ("https://www.sequentra.net/seq-security/ssoLogin.go")

While ie.ReadyState <> 4
    DoEvents
Wend

'''''enter username & password'''''
On Error Resume Next

ie.document.getelementsbyname("j_username").Item.innertext = myusername
ie.document.getelementsbyname("j_password").Item.innertext = mypassword 

'''''submit login info'''''
With appIE
    ie.document.forms(0).submit
End With

'''''click through menus to reports'''''   
'Set frms = ie.document.getelementsbyTagname("FORM")
'Set button = form(0).onsubmit
'form(0).submit

'Set link = ie.document.getelementsbytagname("a")
'For Each l In link
 '   If link.classname = "appReportsShow.do" Then
   '     link.Click
    '    Exit For
    'End If
'Next l

'ie.documents.parentWindow.execScript "loadFrame('appReportsShow.do')", "JavaScript"

'Do While ie.busy: DoEvents: Loop

End With
Set ie = Nothing
End Sub

这是我正在查看的页面源代码:

<li class="clsTopMenuItem active" onmouseover="expandTopMenu(this)" onmouseleave="collapseTopMenu(this)"><a href="javascript:void(0);">My Sequentra</a>                 
    <ul style="display: none;">                     
        <li class="clsSubMenu" onmouseover="expandMenu(this)" onmouseleave="collapseMenu(this)"><a onclick="loadFrame('javascript:goHome()', this, {isNewWindow: false, width:-1, height:-1})" href="javascript:void(0);">Home</a>
        </li>                               
        <li class="clsSubMenu" onmouseover="expandMenu(this)" onmouseleave="collapseMenu(this)"><a onclick="loadFrame('appReportsShow.do', this, {isNewWindow: false, width:-1, height:-1})" href="javascript:void(0);">Reports</a>
        </li>
        <li class="clsSubMenu" onmouseover="expandMenu(this)" onmouseleave="collapseMenu(this)"><a onclick="loadFrame('notificationMyAlertListShow.go', this, {isNewWindow: false, width:-1, height:-1})" href="javascript:void(0);">My Alerts</a>
        </li>
    </ul>                           
</li>

【问题讨论】:

  • 您是否尝试过 .execScript 对整个 javascript 的参数?例如ie.documents.parentWindow.execScript "javascript:loadFrame('appReportsShow.do', this, {isNewWindow: false, width:-1, height:-1});"
  • @Jeeped 我尝试了你的建议,但它仍然停留在我原来的位置,它登录但似乎无法执行 .do 访问报告页面
  • @Jeeped 您是否认为它与鼠标操作有关,因为它是一个悬停下拉菜单?就像我链接的第二个问题一样?
  • 我认为这与鼠标无关,因为我使用 .execScript 在 Web 加载时强制通过动态 JSON 内容。我第一次没有注意到的一件事(不幸的是从您的示例代码中复制的)是您使用的是ie.document►S◄.parentWindow.execScript。应该是ie.Document.parentWindow.execScript
  • @jeeped 找到了解决方案,感谢您的帮助!

标签: javascript html excel vba web-scraping


【解决方案1】:

找到了similar issue on ozgrid,将其用作基点并点击它。解决方案如下。

ie.document.all.Item
Call ie.document.parentWindow.execScript("loadFrame('appReportsShow.do')", "JavaScript")
.Click

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-05
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    相关资源
    最近更新 更多