?
Solved

VBscript to click a link

Posted on 2005-03-15
4
Medium Priority
?
2,261 Views
Last Modified: 2012-08-13
I am in a bit of a quandry.
I am familiar with different types of VBscript that can execute links like document.links(n).click etc.
What I am looking for is a chunk of vbscript that can capture or execute links by their visible text (inner.text?)
so that the VBscript executes a "Go" or "View Details" link, no matter what the href behind it is or what the order is (as the pages are built dynamically).

HELP?

Thanks.
0
Comment
Question by:tbrackett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 13550925
Using VB6 to open IE and clicking an <A> tag knowing the inner text:

To do this you need to add references to
"Microsoft Internet Controls"
"Microsoft HTML Object Library"

Then, as in this example, search for the right <A> tag to click:

Dim ie As InternetExplorer
Dim oHTML As HTMLDocument
Dim oElement As IHTMLElement

Set ie = New InternetExplorer

ie.Visible = True
ie.Navigate "http://www.techsense.com/html/frames/scripts2.html"

Do While ie.ReadyState <> READYSTATE_COMPLETE
    DoEvents
Loop

Set oHTML = ie.Document

'loop through the <a> tags for a specific one
For Each oElement In oHTML.getElementsByTagName("a")
   
    If oElement.innerText = "Example 1" Then '<< change the text to suit your needs
        oElement.Click 'click it!
        Exit For
    End If
   
Next
0
 
LVL 32

Expert Comment

by:Erick37
ID: 13550990
This is better:

For i = 0 To ie.Document.links.Length - 1
   
    If ie.Document.links(i).innerText = "Example 1" Then
        ie.Document.links(i).Click
    End If

Next
0
 

Author Comment

by:tbrackett
ID: 13552231
Great answers thank you!
Erick37 is definitely the simpler solution, but my followup to this is what would be the command for capturing that innerText?
Better stated, what would "get"

ie.Document.links(N).innerText
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 total points
ID: 13554328
MsgBox ie.Document.links(N).innerText

=or=

Dim strText

strText = ie.Document.links(N).innerText
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question