VB Code to Fill Up LogIn Realm

Stonesteel

Board Regular
Joined
Apr 27, 2010
Messages
81
Greetings!

Can anyone help me how to make a vb code that will fill up the login realm when I click a command button? A have a sample here of scenario.

1. First is I have a command button that when I click, it will direct me to the webpage.

Code:
Code:
[FONT=Courier New][COLOR=blue]Sub ip_address()[/COLOR][/FONT]
 
[FONT=Courier New][COLOR=blue] File = "http://" & ActiveCell.Offset(0, 1).Value & ":1080/main.cgi?mac_esn=" & ActiveCell.Value & ""[/COLOR][/FONT]
 
[FONT=Courier New][COLOR=blue]  Call ShellExecute(0&, vbNullString, File, _[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]     vbNullString, vbNullString, vbNormalFocus)[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]End Sub[/COLOR][/FONT]

Image:
http://img171.imageshack.us/img171/4786/activecell.jpg
activecell.jpg


When I click the command button, this will be the url that I will be directed to, url will depend on the value of ActiveCell.Value and ActiveCell.Offset(0, 1)

http://img27.imageshack.us/img27/711/activecell2.jpg
activecell2.jpg


2. Now I will be on the index of the webpage which has a login realm,.

http://img822.imageshack.us/img822/9246/canopyrealm.jpg
canopyrealm.jpg


this is the html code for the login realm.


<form action='login.cgi' method='post' id='quickform'>
<div class='menu' id='quicklogin'>
<input type='hidden' name='mac_esn' value='0a003ef96923' />
<input type='hidden' name='Session' value='0' />
Username: <input type='text' name='CanopyUsername' id='CanopyUsername' /><br/>
Password: <input type='password' name='CanopyPassword' id='CanopyPassword'/><br/>
<input type='submit' value='Login' name='login' id='loginbutton' />
<input type='hidden' value='submit' name='webguisubmit' />
</< div></< color="purple" form>

and this is the username and password that I will be using for example,

Username: sm_inst58132806 (let's say this is located at cell C2)
Password: G4p5n0Xg (let's say this is located at cell D2)

3. Now what I want is to have a code that when I click the command button:

a. will direct me to the webpage
b. automation that will fill up the login realm with given username and password
c. after filling up the realm, will automatically click the submit button and will be directed to the main index.

http://img100.imageshack.us/img100/1592/loginsuccess.jpg
loginsuccess.jpg


hope you could help me on this, I know some of you already knew what code to use when it comes to this one.
 
Check this line in the code again.

Code:
      'navigate to quality of service link
      sUrl = sUrl & "&catindex=1&pageindex=7&Session=" [COLOR="Red"]& sSession[/COLOR]

You appear to have added the variable sUrl here.
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
nope. I didn't add any variable, I just copied what you have given.


'http://172.19.16.8:1080/main.cgi?mac_esn=0a003ef96923&Session=26074
sSession = .LocationUrl
pos = InStr(1, sSession, "Session=", vbTextCompare)
sSession = Trim(Mid(sSession, pos + 8, Len(sSession) - pos + 8))

'navigate to quality of service link
sUrl = sUrl & "&catindex=1&pageindex=7&Session=" & sSession
.Navigate sUrl

i think the code sSession = .LocationUrl is affecting the output URL which makes it invalid. :(
 
Upvote 0
[Edited]
Insert he two lines highlighted in the code below.
If it is not visible click View=>Immediate Window.
Run the code

Code:
      [color=green]'get session number[/color]
      [color=green]'http://172.19.16.8:1080/main.cgi?mac_esn=0a003ef96923&Session=26074[/color]
      sSession = .LocationUrl
      [COLOR="Red"]Debug.Print sSession[/COLOR]
      
      pos = InStr(1, sSession, "Session=", vbTextCompare)
      sSession = Trim(Mid(sSession, pos + 8, Len(sSession) - pos + 8))
      [COLOR="red"]Debug.Print sSession[/COLOR]

Post the two lines that appear in the Immediate Window back here,
 
Upvote 0
Why not click Configuration?

Or grab the URL from there?
 
Upvote 0
Norie, you don't get the idea do you? this project I want to make is "Automation". How can I call this automation if you will click it manually then?
 
Upvote 0
Stonesteel

Did I say manually click it?
 
Upvote 0
OK .LocationUrl is not picking up the session number.

Let's look at Norrie's suggestion to follow the hyperlinks.

Post#4 point 2, configuration menu.
Look at the html, does the configuration menu option have an id?

Post#4 point 3, Quality of Service menu
Look at the html, does the QOS menu option have an id?

If so try amending the code, inserting the id's where highlighted.

Code:
    [color=darkblue]With[/color] objIE
      .Navigate sUrl
      [color=darkblue]Do[/color] [color=darkblue]While[/color] .Busy: DoEvents: [color=darkblue]Loop[/color]
      [color=darkblue]Do[/color] [color=darkblue]While[/color] .ReadyState <> 4: DoEvents: [color=darkblue]Loop[/color]
      .Visible = [color=darkblue]True[/color]
      
      .Document.getElementById("CanopyUsername").Value = sUsername
      .Document.getElementById("CanopyPassword").Value = sPassword
      .Document.getElementById("loginbutton").Click
      
      [color=green]'wait for the previous page to load[/color]
      [color=darkblue]Do[/color] [color=darkblue]While[/color] .Busy: DoEvents: [color=darkblue]Loop[/color]
      [color=darkblue]Do[/color] [color=darkblue]While[/color] .ReadyState <> 4: DoEvents: [color=darkblue]Loop[/color]
      .Document.getElementById("[COLOR="Red"]Configuration_id[/COLOR]").Click
      
      [color=green]'wait for the previous page to load[/color]
      [color=darkblue]Do[/color] [color=darkblue]While[/color] .Busy: DoEvents: [color=darkblue]Loop[/color]
      [color=darkblue]Do[/color] [color=darkblue]While[/color] .ReadyState <> 4: DoEvents: [color=darkblue]Loop[/color]
      .Document.getElementById("[COLOR="red"]QualityOfServive_id[/COLOR]").Click
      
      .Document.getElementById("SubUpkBitCreditRate").Value = 111
      .Document.getElementById("SubDwnkBitCreditRate").Value = 222
      
    [color=darkblue]End[/color] [color=darkblue]With[/color]
 
Upvote 0
Sir bertie, unfortunately those tabs doesn't have any id but instead only href. :(

div id='menu'>
a class='menu' id='menuselect' href="main.cgi?mac_esn=0a003ef96923&catindex=0&pageindex=1&Session=25865">Home</a>
a class='menu' href="main.cgi?mac_esn=0a003ef96923&catindex=1&pageindex=0&Session=25865">Configuration</a>
a class='menu' href="main.cgi?mac_esn=0a003ef96923&catindex=2&pageindex=5&Session=25865">Statistics</a>
a class='menu' href="main.cgi?mac_esn=0a003ef96923&catindex=3&pageindex=0&Session=25865">Tools</a>
a class='menu' href="main.cgi?mac_esn=0a003ef96923&catindex=6&pageindex=0&Session=25865">Accounts</a>
a class='menu' href="main.cgi?mac_esn=0a003ef96923&catindex=8&pageindex=0&Session=25865">PDA</a>
a class='menu' href="main.cgi?mac_esn=0a003ef96923&catindex=9&pageindex=0&Session=25865">Copyright</a>
a class='menu' href="logoff.cgi?mac_esn=0a003ef96923&catindex=0&pageindex=1&Session=25865">Logoff</a>

maybe if we could just capture the session in one of these href I think the code will work. the only problem left here is the session.
 
Upvote 0
Stonesteel

If you can capture the link, you shouldn't need to capture the session.
Code:
Set divMenu = IE.Document.GetelementbyID("menu")
 
Set lnkConfig = divMenu.GetelementsByTagName("A")(1)
 
lnkConfig.Click
 
Upvote 0

Forum statistics

Threads
1,216,038
Messages
6,128,450
Members
449,453
Latest member
jayeshw

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