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>  <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>  <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>  <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?
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.
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??
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"
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:
Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("a")
For Each curElement As HtmlElement In theElementCollection
If curElement.GetAttribute("onclick").Contains("editWL") Then
msgbox(curElement.GetAttribute("onclick")) 'To test with
End If
Next
does that message box look right?