Results 1 to 5 of 5

Thread: How to click on this unique link?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    14

    How to click on this unique link?

    I have a vb app with a webbrowser, and I am trying to search a page with about 1,000 links to click on the right one. Hereare some links from the page source:

    HTML Code:
                                  <tr> 
                                    <td align="center"><input type="checkbox" name="checkedfund" value="9950::Custom"></td>
                                    <td>ING LifeStyle Moderate Growth Portfolio - Service Class</td>
                                    <td>Custom</td>
                                    <td>-</td>
                                    <td>Moderate Allocation</td>                           
                                    <td align="center"><font style='color:black; font-size:9px'>N/App</font></td>    
    								<td><font color='green'>Off Watch List</font>&nbsp;&nbsp<a href="#" onClick="editWL('9950', 'ING LifeStyle Moderate Growth Portfolio - Service Class', 'Custom')">Edit</a></td> 
    								<td align="Center"><a id ='NotesRollover' href="#" onClick="notesWindow('9950', 'ING LifeStyle Moderate Growth Portfolio - Service Class', '-', 'Moderate Allocation', 'Custom','No')" title = 'Edit Notes'>Edit</a>
    								</td>							
                                  </tr>       
    							  
                                  <tr> 
                                    <td align="center"><input type="checkbox" name="checkedfund" value="9951::Custom"></td>
                                    <td>ING LifeStyle Moderate Portfolio - Service Class</td>
                                    <td>Custom</td>
                                    <td>-</td>
                                    <td>Moderate Allocation</td>                           
                                    <td align="center"><font style='color:black; font-size:9px'>N/App</font></td>    
    								<td><font color='green'>Off Watch List</font>&nbsp;&nbsp<a href="#" onClick="editWL('9951', 'ING LifeStyle Moderate Portfolio - Service Class', 'Custom')">Edit</a></td> 
    								<td align="Center"><a id ='NotesRollover' href="#" onClick="notesWindow('9951', 'ING LifeStyle Moderate Portfolio - Service Class', '-', 'Moderate Allocation', 'Custom','No')" title = 'Edit Notes'>Edit</a>
    								</td>							
                                  </tr>       
    							  
                                  <tr> 
                                    <td align="center"><input type="checkbox" name="checkedfund" value="F000002M0A::MF"></td>
                                    <td>American Funds AMCAP R6</td>
                                    <td>MF</td>
                                    <td>RAFGX</td>
                                    <td>Large Growth</td>                           
                                    <td align="center"><font style='color:red; font-size:11px'>X</font></td>    
    								<td><font color='green'>Off Watch List</font>&nbsp;&nbsp<a href="#" onClick="editWL('F000002M0A', 'American Funds AMCAP R6', 'MF')">Edit</a></td> 
    								<td align="Center"><a id ='NotesRollover' href="#" onClick="notesWindow('F000002M0A', 'American Funds AMCAP R6', 'RAFGX', 'Large Growth', 'MF','No')" title = 'Edit Notes'>Edit</a>
    								</td>							
                                  </tr>

    I want to be able to find and click on a link in the page based on its name, like "ING LifeStyle Moderate Growth Portfolio - Service Class" for the first one. Also, I want the second link in each block, with the onClick=notesWindow function. How can I do this?

  2. #2
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: How to click on this unique link?

    My usual: http://stateofidleness.com/2011/01/l...trieve-values/

    you can grab all "a" tags and use GetAttribute "onClick" to get the value of it for further parsing.
    or you can get the InnerHtml of each anchor tag and parse out the second argument of the onClick event using regex or some other method.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    14

    Re: How to click on this unique link?

    I went the first route and got a collection of elements with the "a" tag. But...

    when i do: GetAttribute("onClick") for one of the elements, it returns:

    system.__ComObject


    What is this??

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    14

    Re: How to click on this unique link?

    Also, the other method didnt work for me either

    element.InnerHtml for the "a" tags just returns "Edit"

  5. #5
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: How to click on this unique link?

    can you post the link to the URL (if possible)? it makes it easier to test with.

    are you sure it was InnerHtml and not InnerText?

    this should work:
    vb Code:
    1. Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("a")
    2. For Each curElement As HtmlElement In theElementCollection
    3.    If curElement.GetAttribute("onclick").Contains("editWL") Then
    4.       msgbox(curElement.GetAttribute("onclick")) 'To test with
    5.    End If
    6. Next

    does that message box look right?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width