selecting for a drop downlist

ian0886

New Member
Joined
Dec 10, 2016
Messages
42
Hi,

I'm trying to use VBA to select "Create New IB" from a list of items. Below is what i have right now.

I'm getting an error on the last line. Could anyone please help?

Code:
Sub test2()' open IE, navigate to the desired page and loop until fully loaded
    Set ie = CreateObject("InternetExplorer.Application")
    my_url = "website"


    With ie
        .Visible = True
        .Navigate my_url
        
    Do Until Not ie.Busy And ie.readyState = 4
        DoEvents
    Loop


    End With


' Input the userid and password
    ie.Document.getElementById("login").Value = "testing"
    ie.Document.getElementById("password").Value = "123"


' Click the "Login" button
    ie.Document.getElementById("login-btn").Click


    Do Until Not ie.Busy And ie.readyState = 4
        DoEvents
    Loop
    ie.Document.getElementById("IB")(0).Click
End Sub


This is the java script i got from the website.


HTML:
				<a href="javascript:void(0);">IB</a>				                     <ul>										<li><a href="createib.php">Create New IB</a></li>					 					<li><a href="editib.php">Edit IB Info</a></li>					 					<li><a href="createuserib.php">Create User IB</a></li>					 					<li><a href="createprofile.php">Create New Profile</a></li>
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
getElementById returns a single element, so the array specifier (0) is inappropriate. You haven't posted enough HTML to show where the id "IB" exists, so there might be a shorter way, but try looping through IE.document.links (each link is a HTMLAnchorElement) looking for the link with innerText = "Create New IB" and Click the found link.
 
Upvote 0
Hi John,

Please see below for the HTML code. Sorry i'm fairly new to java. I've added another line below. to click on the inner text IB but its doesn't work. i don't know how to get the cursor to roll over to IB and under it click the createuserib php

Sub testIE()
' open IE, navigate to the desired page and loop until fully loaded
Set ie = CreateObject("InternetExplorer.Application")
my_url = "someurl"


With ie
.Visible = True
.Navigate my_url

Do Until Not ie.Busy And ie.ReadyState = 4
DoEvents
Loop
End With


' Input the userid and password
ie.Document.getElementById("login").Value = "login"
ie.Document.getElementById("password").Value = "password"


' Click the "Login" button
ie.Document.getElementById("login-btn").Click

Do Until Not ie.Busy And ie.ReadyState = 4
DoEvents
Set LinkCollection = ie.Document.GetElementsByTagName("A")
Loop

For Each link In LinkCollection
If link.innertext = "ib" Then
link.Click
Exit For
End If
Next
Do While ie.ReadyState <> 4 Or ie.Busy = True
DoEvents
Loop

End Sub
 
Last edited by a moderator:
Upvote 0
innerText is the displayed menu text, so you need to look for "Create New IB", not "ib". Try this after the login Click:
Code:
    While IE.Busy Or IE.readyState <> 4: DoEvents: Wend
    
    Dim link As Object, createIBlink As Object

    For Each link In IE.document.Links
        If link.innerText = "Create New IB" Then
            Set createIBlink = link
            Exit For
        End If
    Next
    
    If Not createIBlink Is Nothing Then
        createIBlink.Click
        While IE.Busy Or IE.readyState <> 4: DoEvents: Wend
    Else
        MsgBox "Create New IB link not found"
    End If
 
Upvote 0
Hi John,

I tried but its doesn'tlead me to the next page, its states your msg "Create New IB link not found".
 
Upvote 0
Hi John,

i managed to get the page i wanted doing this

Code:
Sub insert()
    Set ie = CreateObject("InternetExplorer.Application")
    my_url = "https://partners.ads-securities.com/admin/login.php"
    my_url2 = "https://partners.ads-securities.com/admin/createib.php"
    With ie
        .Visible = True
        .Navigate my_url
        
    Do Until Not ie.Busy And ie.readyState = 4
        DoEvents
    Loop
    End With
    
    ' Input the userid and password
    ie.document.getElementById("login").Value = "username"
    ie.document.getElementById("password").Value = "X"


' Click the "Login" button
    ie.document.getElementById("login-btn").Click
    
     With ie
        .Visible = True
        .Navigate my_url2
        
    Do Until Not ie.Busy And ie.readyState = 4
        DoEvents
    Loop
    End With
    ie.document.getElementById("username").Value = Range("B8")
    ie.document.getElementById("password").Value = Range("B11")
    ie.document.getElementById("name").Value = Range("B7")
    ie.document.getElementById("lname").Value = " "
    ie.document.getElementById("email").Value = Range("B10")
    ie.document.getElementById("ibcode").Value = Range("B9")
    ie.document.getElementById("region").Value = "'Asia'"
    ie.document.getElementById("currency").Value = "'USD'"
    ie.document.getElementById("balance").Value = "0"
    ie.document.getElementById("IB").Value = Range("B12")
    
    ie.document.getElementById("submitchanges").Click

I have another issue now. For element id "region", as its an option, i can't select asia
below is the html for the page
Code:
<select class="select" name="region" id="region">
	<option value='Abu Dhabi'>Abu Dhabi</option>
	<option value='London'>London</option>
	<option value='Asia'>Asia</option>
	</select>
</div>
<br><br>
<span class="span">Currency:</span>
<div class="input-border">
 
Upvote 0
<select class="select" name="region" id="region">
<option value='Abu Dhabi'>Abu Dhabi</option>
<option value='London'>London</option>
<option value='Asia'>Asia</option>
</select>
</div>
<br><br>
 
Upvote 0

Forum statistics

Threads
1,213,515
Messages
6,114,080
Members
448,548
Latest member
harryls

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top