[VB] How to modify an element's child attribute (Correct Terminology?)

Keydose

New Member
Sep 11, 2013
28
2
I am trying to modify the value of a drop down list on EE's Free Sim page.

Website Code:
Code:
<p class="form-writing">
    <label for="ddlSims">*Number of SIMs</label>
    <select name="ddlSims" id="ddlSims" class="form-layout-select" style="width: 100px;display: block;">
        <option value="1">1</option>
        <option value="2">2</option>

    </select>
</p>

I have got to the point of WebBrowser1.Document.GetElementById("ddlSims").SetAttribute("value", "2") but obviously this doesn't work, as I need to set the option value to 2, any idea how to do this?
 

Keydose

New Member
Sep 11, 2013
28
2
What is it you are trying to achieve?
The html you have posted already has an option for a value of 2
I'm trying to automate a web browser within a VB.NET application so that it selects the second option of the drop down list or sets the drop down list to it's second value.
 

Donkjam

Professional Moderator
Contributor
Nov 20, 2010
1,608
1,603
Try

Webbrowser1.document.GetElementbyId("ddlsims").setattribute("value",1)


Edited

Also It won't work cause using 2 your selecting a 3rd option which ain't there ;)

Edited
 
Last edited:

Keydose

New Member
Sep 11, 2013
28
2
Try

Webbrowser1.document.GetElementbyId("ddlsims").setattribute("value",1)


Edited

Also It won't work cause using 2 your selecting a 3rd option which ain't there ;)

Edited
When using this code I got the same error as before:
Code:
An unhandled exception of type 'System.NullReferenceException' occurred in EE Sim Bot.exe
Additional information: Object reference not set to an instance of an object.
 

Keydose

New Member
Sep 11, 2013
28
2
post your full code
Code:
Private Sub GO()
        i += 2
        ToolStripLabel2.Text = "Active - " & i & "/" & ToolStripTextBox1.Text
        ToolStripProgressBar1.Minimum = 0
        ToolStripProgressBar1.Maximum = ToolStripTextBox1.Text
        ToolStripProgressBar1.Value = i

        If WebBrowser1.DocumentText.ToString().Contains("Just fill in the form and we'll pop your free SIM in the post") Then
            GO()
        ElseIf WebBrowser1.DocumentText.ToString().Contains("Would you be willing to answer a few brief questions about your Order?") Then
            restart()
            WaitForPageLoad()
        End If

        If i >= ToolStripTextBox1.Text Then
            WebBrowser1.Navigate("www.ee.co.uk/freesim")
            i = 0
            ToolStripProgressBar1.Value = 0
            MsgBox("Orders Complete.")
        End If

        WebBrowser1.Document.GetElementById("ddlSims").SetAttribute("value", 1)
        WebBrowser1.Document.GetElementById("txtFirstName").SetAttribute("value", My.Settings.firstname)
        WebBrowser1.Document.GetElementById("txtLastName").SetAttribute("value", My.Settings.lastname)
        WebBrowser1.Document.GetElementById("txtTelephone").SetAttribute("value", My.Settings.telephone)
        WebBrowser1.Document.GetElementById("txtEmail").SetAttribute("value", Environment.TickCount & "@mailinator.com")
        WebBrowser1.Document.GetElementById("txtBuilding").SetAttribute("value", My.Settings.buildingno)
        WebBrowser1.Document.GetElementById("txtEnterPostcode").SetAttribute("value", My.Settings.postcode)
        WebBrowser1.Document.All("btnFind").InvokeMember("click")
        WaitForPageLoad()
        WebBrowser1.Document.GetElementById("lboxSelectAddress").SetAttribute("value", "CENSORED (MY ADDRESS)")
        WebBrowser1.Document.All("btnNext").InvokeMember("click")
        WaitForPageLoad()
        WebBrowser1.Document.All("btnSend").InvokeMember("click")
    End Sub
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
ddlSims is the ID/name of the select box, select boxes do not have the value attribute, instead they have the options, so you will somehow have to traverse through them and when you reach the 2nd option, do something like

Code:
...SetAttribute("selected", "selected")
 

Keydose

New Member
Sep 11, 2013
28
2
ddlSims is the ID/name of the select box, select boxes do not have the value attribute, instead they have the options, so you will somehow have to traverse through them and when you reach the 2nd option, do something like

Code:
...SetAttribute("selected", "selected")
Thanks a lot :)
 

Users who are viewing this thread

Top