Hack Forums
[.NET] [HELP!] VB.NET - Webbrowser - Send a key to webbrowser or Find button (NO ID) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [HELP!] VB.NET - Webbrowser - Send a key to webbrowser or Find button (NO ID) (/showthread.php?tid=2040226)



[HELP!] VB.NET - Webbrowser - Send a key to webbrowser or Find button (NO ID) - Stokerbandit - Dec 23, 2011

I need help to:

Send a key to a webbrowser (Enter key)
OR
When i click Button1 then it clicks a button in the webbrowser that dosnt have ID

Code for button in webbrowser:
PHP Code

<?php 
<input type="submit" value="Log Inn" onmousedown="this.style.backgroundColor='#ddd';" onmouseup="this.style.backgroundColor='#eee';" onmouseover="this.style.backgroundColor='#eee';" onmouseout="this.style.backgroundColor='#fff';" /> 

            </
form> 

Thank You! :)✌


* - System[X] - Dec 23, 2011

Try this

Code
Dim htelcol As HtmlElementCollection = _
  WebBrowser1.Document.GetElementsByTagName("input")
  For Each el As HtmlElement In htelcol
    If el.GetAttribute("type") = "submit" Then
    el.InvokeMember("click")
    End If
  Next

Thanks



* - ibloodqman - Dec 23, 2011

the button doesn't have an "ID" so Stokerbandit if u are coding this put an ID to the button <ex? id="submit" </ex> and use System[X]s' code, else this solution is not working for you
Code
Try this

Code:
Dim htelcol As HtmlElementCollection = _
  WebBrowser1.Document.GetElementsByTagName("input")
  For Each el As HtmlElement In htelcol
    If el.GetAttribute("type") = "submit" Then
    el.InvokeMember("click")
    End If
  Next
//ibloodqman..


* - System[X] - Dec 23, 2011

(Dec 23, 2011 05:10 AM)ibloodqman Wrote:  the button doesn't have an "ID" so Stokerbandit if u are coding this put an ID to the button <ex? id="submit" </ex> and use System[X]s' code, else this solution is not working for you
Code
Try this

Code:
Dim htelcol As HtmlElementCollection = _
  WebBrowser1.Document.GetElementsByTagName("input")
  For Each el As HtmlElement In htelcol
    If el.GetAttribute("type") = "submit" Then
    el.InvokeMember("click")
    End If
  Next
//ibloodqman..

My code used name not ID so it will work. (GetElementsByTagName)

Please read the code again and you will see that it does NOT use ID

Thanks