ie Automaiton/ Hyperlinks/ Question (1 Viewer)

Aubreylc

New member
Local time
Today, 13:34
Joined
Jun 16, 2011
Messages
9
Hello All,

First off, I'm new to the thred.

Second,
I’m wondering if anyone has any suggestions on how to automatically click on a hyperlink when the link itself does not have a ID or Name given to it. With ie automation, you can locate a button on a form and press it by locating its ID.

For example:
The following command will locate the button within the form that has an ID of “Button1” and will then click it.

ie.Document.all("Button1").Click

Because I’m trying to click within a dynamically generated table, the links do not have specific ID’s.

This is a sample of the table with its links:
PHP:
<div class=centered>
PHP:
[SIZE=3][FONT=Calibri]<TABLE id=Table1 cellSpacing=0 cellPadding=0 width="100%" border=0>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]  <TR>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]    <TD><p class=title>  [/FONT][/SIZE]
[SIZE=3][FONT=Calibri]      Dropship Orders</p></TD></TR></TABLE>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<!-- begin list -->[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<p></p><span id="lblGrid"><table class='core' style='width:650px;'>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<tr class='header'><td>Vendor</td><td>Ready For Vendor</td><td>At Drop Shipper</td><td>Not Ready</td><td>Total</td></tr>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<tr><td class='core'><b>2XLCORP   </b></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=2XLCORP&filter=PURC&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=2XLCORP&filter=DROP&cnt=8' style='margin-right: 100px;'>8</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=2XLCORP&filter=OTHER&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=2XLCORP&filter=ALL&cnt=8' style='margin-right: 100px;'>8</td></tr>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<tr><td class='core'><b>AARCOPRO  </b></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=AARCOPRO&filter=PURC&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=AARCOPRO&filter=DROP&cnt=2' style='margin-right: 100px;'>2</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=AARCOPRO&filter=OTHER&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=AARCOPRO&filter=ALL&cnt=2' style='margin-right: 100px;'>2</td></tr>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<tr><td class='core'><b>ACCENTS   </b></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ACCENTS&filter=PURC&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ACCENTS&filter=DROP&cnt=5' style='margin-right: 100px;'>5</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ACCENTS&filter=OTHER&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ACCENTS&filter=ALL&cnt=5' style='margin-right: 100px;'>5</td></tr>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<tr><td class='core'><b>ACME      </b></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ACME&filter=PURC&cnt=1' style='margin-right: 100px;'>1</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ACME&filter=DROP&cnt=9' style='margin-right: 100px;'>9</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ACME&filter=OTHER&cnt=1' style='margin-right: 100px;'>1</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ACME&filter=ALL&cnt=11' style='margin-right: 100px;'>11</td></tr>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<tr><td class='core'><b>ALLNONE   </b></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ALLNONE&filter=PURC&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ALLNONE&filter=DROP&cnt=4' style='margin-right: 100px;'>4</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ALLNONE&filter=OTHER&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ALLNONE&filter=ALL&cnt=4' style='margin-right: 100px;'>4</td></tr>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<tr><td class='core'><b>AMANO     </b></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=AMANO&filter=PURC&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=AMANO&filter=DROP&cnt=3' style='margin-right: 100px;'>3</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=AMANO&filter=OTHER&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=AMANO&filter=ALL&cnt=3' style='margin-right: 100px;'>3</td></tr>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<tr><td class='core'><b>AMFRAME   </b></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=AMFRAME&filter=PURC&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=AMFRAME&filter=DROP&cnt=2' style='margin-right: 100px;'>2</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=AMFRAME&filter=OTHER&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=AMFRAME&filter=ALL&cnt=2' style='margin-right: 100px;'>2</td></tr>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<tr><td class='core'><b>ANDERCO   </b></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ANDERCO&filter=PURC&cnt=6' style='margin-right: 100px;'>6</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ANDERCO&filter=DROP&cnt=62' style='margin-right: 100px;'>62</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ANDERCO&filter=OTHER&cnt=12' style='margin-right: 100px;'>12</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=ANDERCO&filter=ALL&cnt=80' style='margin-right: 100px;'>80</td></tr>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<tr><td class='core'><b>BAGMAKE   </b></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=BAGMAKE&filter=PURC&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=BAGMAKE&filter=DROP&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=BAGMAKE&filter=OTHER&cnt=1' style='margin-right: 100px;'>1</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=BAGMAKE&filter=ALL&cnt=1' style='margin-right: 100px;'>1</td></tr>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<tr><td class='core'><b>BCT       </b></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=BCT&filter=PURC&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=BCT&filter=DROP&cnt=1' style='margin-right: 100px;'>1</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=BCT&filter=OTHER&cnt=1' style='margin-right: 100px;'>1</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=BCT&filter=ALL&cnt=2' style='margin-right: 100px;'>2</td></tr>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<tr><td class='core'><b>BEELINER  </b></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=BEELINER&filter=PURC&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=BEELINER&filter=DROP&cnt=1' style='margin-right: 100px;'>1</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=BEELINER&filter=OTHER&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=BEELINER&filter=ALL&cnt=1' style='margin-right: 100px;'>1</td></tr>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<tr><td class='core'><b>BICGRAPH  </b></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=BICGRAPH&filter=PURC&cnt=0' style='margin-right: 100px;'>0</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<td class='core'><a href='orders.aspx?vendorno=BICGRAPH&filter=DROP&cnt=8' style='margin-right: 100px;'>8</a></td>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]</table>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]</span><BR><BR><BR>[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]<!-- end list --></div></form></div>[/FONT][/SIZE]
 
that's ACTUAL PHP code??

if it is, you're going to have to loop the <a> tags after the document loads completely. PHP is executed first, as it's on the server, and HTML/JS/etc... is executed after that because it's on the server side. Hence, PHP code will not be available in the source code of the webpage.

You have the PHP code, so you know what the links are supposed to say. when you loop the <a> tags, set a breakpoint at the conditional where you check the links with the INSTR() function. you can loop links with the .LINKS collection, or with a long and the .LENGTH property of the collection.

see here for more help: http://www.access-programmers.co.uk/forums/showthread.php?t=176968
 
Last edited:
that's ACTUAL PHP code??

I'ts not PHP. I made a mistake by wrapping it in PHP tags. In each href only part of the link is consistent


I am very new to this so please forgive me for sounding like a ludite. It would help if someone can break this process down.


1.This is the link I need to Click
<a href='orders.aspx?vendorno=2XLCORP&filter=PURC&cnt=0'

2.This part of the link is constant.
'orders.aspx?vendorno=2XLCORP&filter=PURC&cnt=

3.This part of the link is a random variable.
0

 
I Almost have it -- Automaiton/ Hyperlinks/ Question

This is what I have so far. Really if someone can chime in, it would help alot.


To select only this link:
Code:
[COLOR=#0000ff]<[/COLOR][COLOR=#800000]td[/COLOR][COLOR=#ff0000]class[/COLOR][COLOR=#0000ff]='core'>[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]a[/COLOR][COLOR=#ff0000]href[/COLOR][COLOR=#0000ff]='orders.aspx?vendorno=CFFLAG&filter=PURC&cnt=9' [/COLOR][COLOR=#ff0000]style[/COLOR][COLOR=#0000ff]='margin-right: 100px;'>[/COLOR]9[COLOR=#0000ff]</[/COLOR][COLOR=#800000]a[/COLOR][COLOR=#0000ff]>[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]td[/COLOR][COLOR=#0000ff]>[/COLOR]
I used the following code. The code only finds the first url in the page and then stops though.



Code:
Private Sub btnAlainsMethod_Click()
Dim appIE As Object ' InternetExplorer.Application
Dim sURL As String
Dim ElementCol As Object ' MSHTML.IHTMLElementCollection
Dim Link As Object ' MSHTML.HTMLAnchorElement
'Application.ScreenUpdating = False
Set appIE = CreateObject("InternetExplorer.Application")
sURL = "Url_Dot_Com"
With appIE
    .Navigate sURL
    ' uncomment the line below if you want to watch the code execute, or for debugging
   .Visible = True
End With
' loop until the page finishes loading
Do While appIE.Busy
Loop
' click a text link on the page after that
Set ElementCol = appIE.Document.getElementsByTagName("a")
For Each Link In ElementCol
    If Link.innerHTML = "<B>CFFLAG</B>" Then [text between > and < like ...>PURC</a> ]
        Link.Click
        Exit For
 
Next Link
 
End Sub
 
what o you mean about the random number being a variable?? if it is, why dont you just concat the entire string together and go to the URL using the .navigate property of your ie obj?
 
I wouldn't even know how to begin concatinating it. I'm sorry to sound like such a looser but as i said earlier, i'm very new to programming in general. A bunch of people in my dept. were fired and I have to come up with creative ways to automate routine processes because i'm now having to pick up their workload.
 
I see. so state it again. WHAT do you want? since you're a newbie, maybe these questions will help you:

  • what does that VARIABLE (that you speak of) have to do with this whole thing? e.g. - where does it come from? I know it's part of the query string in the URL that you want to access, but does that PHP criteria come from your vba code, or from user input on the webpage??
  • what URL are you working with? e.g. - the URL that provides the link that you WANT to click on.

if you answer those, I can probably give you a solution, although I hate doing that. But you sound legitimate. But that's only my guess of course!
 
I've attached a .doc file which illustrates the process in greater detail --I hope anyway. I know that there are alternatives but they would require our IT dept. to get involved. Our IT staff is thin and working on a ERP project for a sister company.
 

Attachments

well my friend, that doc doesn't answer any of the ?'s I asked you. sorry.

if you answer the ?'s, I'll help. if you don't know HOW to answer them, you might want to say so. ;)
 
1. The variable represents the number of documents that need to be submitted and it does not come from the VBA code.

2. The url that I'm working with is this:
<ahref='orders.aspx?vendorno=CFFLAG&filter=PURC&cnt=9'

 
by URL, I means the actual website you are working with. make sense? give me that please.

this q string:

PHP:
<ahref='orders.aspx?vendorno=CFFLAG&filter=PURC&cnt=9'

that you mentioned seems like you're looking at your vendor purchases online.

but at any rate, back to what I said earlier, if your variable of "9" does NOT come from the website's previous page via and an input element (like text box or something), you can go to this page simply by navigating in your vba code:

Code:
ieObj.navigate "www.websitename.com/anySubFolder/orders.aspx?vendorno=CFFLAG&filter=PURC&cnt=9"

see what I mean? I want your address so I can actually CLICK on the link you want and show you how from vba. and the URL I want is the actual webpage that produces these "orders.aspx?" links that you can click on. make sense again?
 
Hi Aubreylc,

From my reading of the thread you need to be very specific on what you want. IE automation is not easy and is not black and white as you have found out. There is no ID so we need to make guesses about what the server will give IE and make assumptions based on that.

1. Is the web page public?
2. If yes what is it and what is the EXACT page you are trying to automate
3. If it is not public can you open the page in FireFox or IE and save the page as HTML and then give us this page.
4. If you cannot do this can you VIEW SOURCE and then copy the whole page into a text file and add that to this thread.
5. Next (and assuming you have given us a full file of the html) what EXACTLY do you want to click on WHEN YOU VIEW IT IN IE.
6. It appears you are a little more advances at finding this in the html so you can also show the full html tags around the link - I would say from the <TD> would be enough.

Once we are all on the same page then we can get into whether it changes, or not and how it changes etc.

I (and the-net-2.0) have been on a number of threads helping people with automating IE. In my opinion if you cannont answer 1,3,4 above it makes it very hard in my opinion and I am less interested in helping.
 
1. The web page is not public.
2. The file is attached and I renamed it as a .txt file.
3. The link I want to click on is:
Code:
<td class='core'><a href='orders.aspx?vendorno=CFFLAG&filter=PURC&cnt=5' style='margin-right: 100px;'>5</a></td>


Thanks for your help.
 

Attachments

so you want to click on the link in the first column named "ready for vendor" for CFFLAG?

so now why?

what is the criteria ? Vendor name and column or what.

Of do you always want to click on the first colum for CFFLAG
 
actually looking at the page I think it is pretty easy.

Basically the HREF is a pretty good id

vendorno=CFFLAG&filter=PURC&cnt
CFFLAG is the name
PURC - is the column

I would follow what you have already started but just use "instr"

To build flexibility you can use a select for the columns like this - you cannot cut and copy this but you should get the idea.

Dim searchString as String

searchString = "CFFLAG&filter="


Select userChoice
case "ready for vendor"
searchString = searchString & "PURC"
case "at drop shipper"
searchString = searchString & "DROP"
case "not ready"
searchString = searchString & "OTHER"
case "total"
searchString = searchString & "ALL"
End Select


Then when you look at your link use this

If InStr(yourlinkinnertext, searchstring) Then
MsgBox "you have the Right link you can click on it"
End If
 
hey bud,

I finally did a test for you. Here is an example from google. take this code:

Code:
Function test()

Dim i As Long
Dim ie As Object
Dim link As Object

Set ie = CreateObject("internetexplorer.application")

ie.Visible = True
ie.Navigate "http://www.google.com"

  While ie.busy
    DoEvents  'wait until IE is done loading page.
  Wend

With ie.Document
    For i = 0 To .links.length - 1
        Debug.Print i & " - " & .links(i) & .links(i).innerhtml
    Next i
End With

ie.Close

Set ie = Nothing

End Function

and in the immediate window, the simple links that just have words on them (e.g. - simple <a> tags with HREFs that are being used to display links) printed this out:

Code:
40 - http://www.google.com/services/Business Solutions - Business Solutions
41 - http://www.google.com/intl/en/about.htmlAbout Google - About Google
42 - http://www.google.com/intl/en/privacy.htmlPrivacy - Privacy
43 - javascript:void(0)Change background image - Change Background Image

so there ya have it! If I want to click on the link on google's homepage that says "Change Background Image", I'm gonna write this:

Code:
With ie.Document
    .links(43).Click
End With

so do it for yourself now. take my code as an example and loop your own links. this is one of the first things I said to you. If you can get the index number of the link you want, that's all you need.
 

Users who are viewing this thread

Back
Top Bottom