vb.net - Unable to to locate and click a submit button using mshtml.HTMLInputElement -



vb.net - Unable to to locate and click a submit button using mshtml.HTMLInputElement -

below is html form , below that, vb procedure, "loginexamp" enters in username , password. unable locate button , click since not seem show mshtml.htmlinputelement. "htmlinput.click()" never runs. how can adjust loginexamp code button clicked. help.

<form id="loginform" name="loginform" method="post" action=""> <input id="username" class="formfield" type="text" value="user name" maxlength="40" name="xusername"> <input id="password" class="formfield" type="password" onfocus="cleardefault(this)" maxlength="40" name="xpassword"> <button class="subbutton" onclick="javascript: submitform()">submit!</button> </form>

with below code

public sub loginexamp() dim objie shdocvw.internetexplorer dim htmldoc mshtml.htmldocument dim htmlinput mshtml.htmlinputelement dim htmlcoll mshtml.ihtmlelementcollection dim url object url = "http://localhost/buttonclicktest.html" 'just test page loginform above objie = new shdocvw.internetexplorer objie .navigate(url) .visible = true while .busy = true threading.thread.sleep(2000) end while htmldoc = .document htmlcoll = htmldoc.getelementsbytagname("input") while .busy = true threading.thread.sleep(2000) end while each htmlinput in htmlcoll if htmlinput.name = "xusername" htmlinput.value = "theusername" 'this works elseif htmlinput.name = "xpassword" htmlinput.value = "thepassword" 'this works end if if htmlinput.classname = "subbutton" 'this never true htmlinput.click() 'this line never runs end if next htmlinput end end sub

i able figure out reply own question. below code works. both username , password entered , button clicked.

public sub loginexamp() dim objie shdocvw.internetexplorer dim htmldoc mshtml.htmldocument dim htmlinput object dim url string url = "http://localhost/n1/buttonclicktest.html"'test page loginform above objie = new shdocvw.internetexplorer objie .navigate(url) .visible = true while .busy = true threading.thread.sleep(2000) end while htmldoc = .document dim htmlcoll mshtml.htmlformelement = directcast(htmldoc.forms.item("loginform"), mshtml.htmlformelement) while .busy = true threading.thread.sleep(2000) end while each htmlinput in htmlcoll if htmlinput.name = "xusername" htmlinput.value = "theusername" elseif htmlinput.name = "xpassword" htmlinput.value = "thepassword" end if if htmlinput.classname = "subbutton" htmlinput.click() end if next htmlinput end end sub

vb.net visual-studio browser

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -