我如何使用超链接的名称或标题来访问它

发布于 2024-12-14 05:18:45 字数 1137 浏览 2 评论 0原文

在我的测试中,我需要使用超链接浏览网站,其名称(和标题)是“下一个”。我从我的应用程序中添加了它,并使用了“单击”方法。它仅在第一次工作,因此浏览器导航到第二页并卡在那里。我的代码如下:

Do 
    Set msgList = Browser("Incoming — Gmail").Page("ВIncoming — Gmail").ChildObjects(msgDesc)
    msgCount = msgCount + msgList.Count()

    Reporter.ReportEvent micPass, "MessagesCount", "Messages: " & msgCount

    'MsgBox msgList.Count() ' in a purpose of debugging

Loop While SurfNextPage(Browser("Incoming — Gmail").Page("Deliver successfull"))

'Function surfs to the next page, if it possible
' currPage -- current page
'Return: TRUE, if  link to the next page is available, otherwise ELSE
Function SurfNextPage(currPage)
Dim bResult

   Set hlDesc = Description.Create
   hlDesc("name").Value = "next"

   Set hlList = currPage.ChildObjects(hlDesc)
   For i = 0 to (hlList.Count()-1)
       Set urlNextMail  = hlList(i)     'there would be the only element in list

   Next

   bResult   = urlNextMail.Exist

   If bResult Then
       urlNextMail.Click 'surfs to the next page

   End If

   SurfNextPage = bResult

End Function

该网页的结构很困难——有很多DIV和Java,所以我不能确切地说这个链接属于哪个框架或表,但没有其他同名的链接。

in my test, i need to surf through site, using hyperlink, which name (and the caption) is 'next'. I added it from my application, and used a 'click' method. It is working only for the first time, so browser navigated to the second page and had stucked there. My code is below:

Do 
    Set msgList = Browser("Incoming — Gmail").Page("ВIncoming — Gmail").ChildObjects(msgDesc)
    msgCount = msgCount + msgList.Count()

    Reporter.ReportEvent micPass, "MessagesCount", "Messages: " & msgCount

    'MsgBox msgList.Count() ' in a purpose of debugging

Loop While SurfNextPage(Browser("Incoming — Gmail").Page("Deliver successfull"))

'Function surfs to the next page, if it possible
' currPage -- current page
'Return: TRUE, if  link to the next page is available, otherwise ELSE
Function SurfNextPage(currPage)
Dim bResult

   Set hlDesc = Description.Create
   hlDesc("name").Value = "next"

   Set hlList = currPage.ChildObjects(hlDesc)
   For i = 0 to (hlList.Count()-1)
       Set urlNextMail  = hlList(i)     'there would be the only element in list

   Next

   bResult   = urlNextMail.Exist

   If bResult Then
       urlNextMail.Click 'surfs to the next page

   End If

   SurfNextPage = bResult

End Function

The web-page has a difficult structure -- a lot of DIV and Java, so i can't say exactly to which frame or table this link belongs, but there are no another links with the same name.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丑疤怪 2024-12-21 05:18:45

经过一番评论后,最后一页上似乎存在下一个链接,但单击它没有任何反应。

您应该修改正在使用的描述,以便识别链接,以便它仅匹配移至下一页的链接,而不匹配最后一页上不可见(但存在)的链接。


原始答案:
由于您始终使用同一页面来调用 SurfNextPage,因此此方法应该有效(假设该页面下的对象存储库中有一个 "next" 链接)。

如果您想使用不同的页面,那么您应该使用描述性编程,即不使用存储库中的对象,而是使用类似这样的 currPage.Link("text:=next") 这将查找以 "next" 作为其文本属性的链接。

另一件可能出错的事情是在导航之前识别对象,然后导航使该对象无效。如果是这种情况,您应该使用 RefreshObject 方法(如文档中所述)。

如果这些建议都没有帮助,请提供更多关于到底是什么被“卡住”的信息

After some back and forth in the comments it appears that the next link does exist on the last page but clicking it does nothing.

You should modify the description you're using in order to identify the link so that it only matches links that move to the next page and not the link that is invisible (but there) on the last page.


Original answer:
Since you're always using the same page to call SurfNextPage then this method should work (assuming there is a "next" link in the object repository under said page).

If you want to use different pages then you should use descriptive programming, i.e. not use an object from the repository, instead use something like this currPage.Link("text:=next") this will look for a link with "next" as its text property.

Another thing that may be going wrong is that an object is identified before a navigation and then the navigation invalidates the object. If this is the case you should use the RefreshObject method (as explained in the documentation).

If none of these suggestions help please provide more information on what exactly is getting "stucked"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文