Start New Discussion within our Software Development Community

I'm trying to automate browser at google website,

There are several expiration dates in the drop down list. If you choose one, the option table below is updated accordingly. The website script is listed below.

<div id="expirations" class="id-expirations float sfe-break-left">
<option value="0">Jan 21, 2012</option>
<option value="1">Jan 27, 2012</option>
<option value="2">Feb 18, 2012</option>
<option value="3">Mar 17, 2012</option>
<option value="4">Jun 16, 2012</option>
<option value="5">Jan 19, 2013</option>
<option value="6">Jan 18, 2014</option>

Here is my VB code. It can find the drop down list, but even I used SetAttribute, the website is not updating. For example the code choose the last expiration date, but the option table still shows the first expiration table. How should I update the option table in Anyone can help? Thanks

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        If Me.WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
            Dim StrikeExpiry As HtmlElement
            StrikeExpiry = WebBrowser1.Document.GetElementById("expirations")
            TextBox2.Text = StrikeExpiry.All.Count - 1 'the number of expiry
            'TextBox2.Text = StrikeExpiry.InnerText

            For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("select")
                element.SetAttribute("value", StrikeExpiry.All.Count - 2)

        End If

    End Sub

Use Selenium IDE to automate such tasks(It's a plugin for firefox) ,you would never require to write this much senseless code and break your head.

Record a selenium macro,before running it just add a command to set execution interval belween each dorop down click as Command:setSpeed and target:6000 leave value: as blank....see attachment. Run it

Attachments selenium.png 27.98 KB
This article has been dead for over six months. Start a new discussion instead.