2016-07-11 273 views
-1

我正在进行一个登录程序到一个Intranet站点的自动化,我已经编写了进入该网站的代码。发布有一堆选项,其中有java查询运行onclick。我无法这样做,我检查了多个帖子并尝试了吹码但没有运气。VBA点击一个链接使用href

Do While IE.Busy 
Loop 
' click a text link on the page after that 
Call objIE.document.frames(1).document.parentWindow.execScript("javascript:void(0)", "JavaScript") 
End Sub 
  • 也是我一直在使用getelementbyclassname试过了,那也没有工作。

有人可以帮助这个。

下面

是基于web

class="appLaunch">Full Screen Desktop</a></p></td><td></td></tr></table></td></tr><tr><td class="appsCell" colspan="5"><table class="appsTable" border="0" cellpadding="0"><tr><td width="12" align="left" valign="top">&nbsp;</td><td><span class="navareaSessionGif"><a href="javascript:void(0);" onclick="OnAppKeyPress(event, '../../../applicationLaunch/appLaunch.jsp?launchobject=...%2F_ens%2Fo%3Dapplications%2Fou%3DCDM%2Fou%3Dswi7%2Fcn%3DFull+Screen+Desktop+Drive+Map&SGD_Token=avFjUXXu5v_704onY8odrN2dW8IuTwBB', 'ResponseFrame', '.../_ens/o=applications/ou=CDM/ou=swi7/cn=Full Screen Desktop Drive Map')" target="ResponseFrame" title="Always resumable, displays full-screen (1 session(s))"><img src="/sgd/cust_resources/images/icons/windows.gif" alt="Full Screen Desktop Drive Map" border="0" class="icon" /></a></span></td><td width="18" align="left"><span class="navareaSessionGif"></span></td><td nowrap><p class="navareaApp"><a href="javascript:void(0);" onclick="OnAppKeyPress(event, '../../../applicationLaunch/appLaunch.jsp?launchobject=...%2F_ens%2Fo%3Dapplications%2Fou%3DCDM%2Fou%3Dswi7%2Fcn%3DFull+Screen+Desktop+Drive+Map&SGD_Token=avFjUXXu5v_704onY8odrN2dW8IuTwBB', 'ResponseFrame', '.../_ens/o=applications/ou=CDM/ou=swi7/cn=Full Screen Desktop Drive Map')" target="ResponseFrame" title="Always resumable, displays full-screen (1 session(s))" 

回答

0

您可以编辑和尝试下面的代码的源代码:

Dim ElementCol, txt As Object 
Set ElementCol = objIE.Document.frames(1).Document.getElementsByTagName("a") 
    For Each txt In ElementCol 
     If txt.innerText = "Full Screen Desktop" Then 
      txt.Click 
      Exit For 
     End If 
    Next 
+0

感谢您快速输入,但它仍然没有工作,示值误差不能找到对象和调试停止在 - 设置ElementCol = objIE.document.frames(1).document.getElementsByTagName(“a”) –

+0

@ JB我也尝试了这一点,当IE完成加载 - Dim LinkFound作为布尔 昏暗linkCollection 设置linkCollection = IE.document.getElementsByTagName( “A”) 为每个链接在linkCollection 如果link.innerText = “全屏桌面驱动器映射” 然后 LinkFound =真 link.Click 退出对于 结束如果 接下来 如果没有链接然后 MsgBox“未找到链接!” 退出小组 结束如果 做,直到IE.readyState = 4 的DoEvents 循环 结束小组 ----------和它说没有找到的链接。所以这不是一个按钮或链接....以下是该页面的完整代码------ –

+0

请按照框架编辑代码。您可以用框架(“框架名称”)替换框架(1)。如果帧内存在帧,则必须通过给出两个名称来编写适当的帧路径。 –