Usuário com melhor resposta
Preciso fazer um click em um button pelo class

Pergunta
-
Então galera estou tentando fazer o click no button pelo class utilizando o webbrowser do visual basic com esse código aqui, mais ele simplesmente não clicka e eu não entendo o porque.. se puderem me ajudar agradeço.
Dim PageElement1 As HtmlElementCollection = WebBrowser1.Document.All.GetElementsByName("btn btn-primary") For Each CurElement1 As HtmlElement In PageElement1 CurElement1.InvokeMember("click") Next
esse aqui é o código do button no site
<button type="submit" class="btn btn-primary">Entrar</button>
Quem puder me ajudar eu agradeço.
Respostas
-
Vou colocar ele em VB.Net
Dim PageElement1 As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("button") For Each CurElement1 As HtmlElement In PageElement1 If CurElement1.GetAttribute("className") = "btn btn-primary" Then CurElement1.InvokeMember("click") End If Next
Espero ter ajudado! Se consegui, não esquece de marcar no fórum como útil! Obrigado :)
#fullstack dev - MCSA, MCTS and actually blogging at www.saindodacaixinha.com.br- Marcado como Resposta Mente Viva quinta-feira, 19 de julho de 2018 19:32
Todas as Respostas
-
O WebBrowser não permite pegar elementos pela Class.
A alternativa é pegar os elementos button, iterar neles fazendo o click.
var buttons = webBrowser1.Document.GetElementsByTagName("button"); foreach (HtmlElement button in buttons) { if (button.GetAttribute("className") == "btn btn-primary") { //do something } }
Espero ter ajudado! Se consegui, não esquece de marcar no fórum como útil! Obrigado :)
#fullstack dev - MCSA, MCTS and actually blogging at www.saindodacaixinha.com.br -
O WebBrowser não permite pegar elementos pela Class.
A alternativa é pegar os elementos button, iterar neles fazendo o click.
var buttons = webBrowser1.Document.GetElementsByTagName("button"); foreach (HtmlElement button in buttons) { if (button.GetAttribute("className") == "btn btn-primary") { //do something } }
Espero ter ajudado! Se consegui, não esquece de marcar no fórum como útil! Obrigado :)
#fullstack dev - MCSA, MCTS and actually blogging at www.saindodacaixinha.com.brAmigo inseri o código dentro do meu programa, e ele mostrou diversos erros de sintaxe.. se puder me ajudar a corrigir isso eu agradeço.
Gostaria de colocar uma imagem mostrando melhor os erros, porém o fórum não me permite.
Error 11 Syntax error.
Error 12 Syntax error
Error 13 Syntax error.
-
Vou colocar ele em VB.Net
Dim PageElement1 As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("button") For Each CurElement1 As HtmlElement In PageElement1 If CurElement1.GetAttribute("className") = "btn btn-primary" Then CurElement1.InvokeMember("click") End If Next
Espero ter ajudado! Se consegui, não esquece de marcar no fórum como útil! Obrigado :)
#fullstack dev - MCSA, MCTS and actually blogging at www.saindodacaixinha.com.br- Marcado como Resposta Mente Viva quinta-feira, 19 de julho de 2018 19:32