1

I am new to excel vba programing. I have been trying to click on a hyperlink on a web page using excel vba from almost 3 days now. Please help me out. Since I am new to this I might have made a lot of blunders. Pardon me for that.

The scenario is : A particular web page has a table with first column as an icon, second column is a hyperlink and a few more columns with some description about the hyperlink.

Now, I want to click on the hyperlink in the first row (second column). When we hover over the icon present in the same row(in first column) the same hyperlink is displayed.

This webpage is dynamic, hence the table keeps changing. Actually the table is a result of a search criteria entered.

I have written a lot of codes from three days. This is the latest one thats not working:

'Get element id for the row

With elementid = ieApp.document.all.Item("abcrow1")
   'checking for details with tagname as "a"
   Set tagname = ieApp.document.getElementByTagName("a")

   For Each tag In tagname
     'Get value of the href
     hrefvalue = tag.href.value
   If Not IsNull(hrefvalue) Then
     If hrefvalue <> "javascript:void(0);" Then  'this href is usedto describe the icon
        hrefvalue = ieApp.document.href.value

        hrefvalue = "https://www.secur.com" & hrefvalue
        ieApp.Navigate hrefvalue
        Exit For
     End If
   End IF
Next tag
End With

The HTML script is as follows:

 <tr id = "abcrow1" class="e1">
   <td class = "icon"></td>
   <td><ul class="xyz" id="link">
       <li><a href = "javascript:void(0);"><img src="/nnn.gif" border = 0 alt = "info"         </a>
       <ul>
       <li><a onclick ="return cursorWait(this);" href = "/xyz/lmo">DetailOfRow1</a></li></ul></td>
   <td style = "text-align:left"><aonclick="return cursorWait(this);" href = "/xyz/lmo">DetailOfRow1</a></td></tr>

Please help me out. Thank you.

Community
  • 1
  • 1
user3174245
  • 103
  • 2
  • 2
  • 7

1 Answers1

0

Does this work? If not, what do hrefvalue_1 and hrefvalue_2 evaluate to?

Set Tagname = ieApp.document.getElementsByTagName("a")
For Each Tag In Tagname
    If InStr(1, Tag.innertext, "DetailOfRow1", vbTextCompare) > 0 Then
        hrefvalue_1 = Tag     ' tag may contain "about:", if so remove it
        hrefvalue_2 = Replace(Tag, "about:", "", 1, -1, vbTextCompare)
        hrefvalue_3 = "https://www.secur.com" & hrefvalue_2
        ieApp.Navigate hrefvalue
        Exit For
    End If
Next Tag

It's a little hard to finalize without acces to the url, but something along these lines should work...

With elementid = ieApp.document.all.Item("abcrow1")
 'checking for details with tagname as "a"
 Set tagname = ieApp.document.getElementByTagName("a")

 For Each tag In tagname
   'Get value of the href
  If InStr(1, tag.getAttribute("href"), "javascript:void(0);", vbTextCompare) = 0 Then       
     hrefvalue = tag
     hrefvalue = "https://www.secur.com" & hrefvalue
     ieApp.Navigate hrefvalue
     Exit For
  End If
 Next tag
End With
ron
  • 1,456
  • 3
  • 18
  • 27
  • Thanks. Alot of my problems have been solved after incorporating your suggestion. But I am still unable to navigate to the link mentioned in the last line of the html code. ` – user3174245 Jan 12 '14 at 17:07
  • How do i get the attribute style? Is this right because it doesnt seem to be working: `If Instr(1,tag.getAttribute("Style"),"tex-align:left",vbTextCompare)<>0 Then` navigate to link in href. – user3174245 Jan 12 '14 at 17:28