2
I’m having trouble sending values to a form via Web Browser
. My goal is to make a post, IE, send the values to inputs
of the form and do the submit
from the same, after this open the page generated in my browser.
Form:
<form action="..." method="post" accept-charset="ISO-8859-1" name="postmodify" id="postmodify" class="flow_hidden" onsubmit="submitonce(this);smc_saveEntities('postmodify', ['subject', 'message', 'guestname', 'evtitle', 'question'], 'options');" enctype="multipart/form-data">
<input type="text" name="subject" tabindex="1" size="80" maxlength="80" class="input_text" />
<select name="icon" id="icon" onchange="showimage()">
<option value="xx" selected="selected">Padrão</option>
<option value="thumbup">OK</option>
<option value="thumbdown">Negativo</option>
<option value="exclamation">Ponto de exclamação</option>
<option value="question">Ponto de interrogação</option>
<option value="lamp">Lâmpada</option>
<option value="smiley">Sorridente</option>
<option value="angry">Zangado</option>
<option value="cheesy">Contente</option>
<option value="grin">Sorriso forçado</option>
<option value="sad">Triste</option>
<option value="wink">Piscar</option>
</select>
<textarea class="resizeble" name="message" id="message" rows="12" cols="600" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);" tabindex="2" style="height: 175px; width: 100%; "></textarea>
<input type="submit" value="Enviar" tabindex="3" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit" />
</form>
C#:
WebBrowser oWebBrowser = new WebBrowser();
oWebBrowser.ScriptErrorsSuppressed = true;
oWebBrowser.Navigate("meulink");
//botão para fazer postagem
private void postar_Click(object sender, EventArgs e)
{
try
{
HtmlElement subject = oWebBrowser.Document.GetElementsByTagName("input")["subject"];
if(subject != null)
{ //tentativa de setar o subject
subject.SetAttribute("value", assunto);
MessageBox.Show("assunto");
}
HtmlElement ico = oWebBrowser.Document.GetElementById("icon");
if (ico != null)
{ //tentativa de setar o icon
ico.SetAttribute("value", m.traduzIcon(icon.Text));
MessageBox.Show("icon");
}
HtmlElement message = oWebBrowser.Document.GetElementById("message");
if (message != null)
{ //tentativa de setar o message
message.InnerText = padrao;
MessageBox.Show("padrao");
}
HtmlElement form = oWebBrowser.Document.GetElementById("postmodify");
if (form != null)
{ //tentativa de dar submit
form.InvokeMember("submit");
MessageBox.Show("submit");
}
//tentativa de abrir o link da postagem
ProcessStartInfo post = new ProcessStartInfo(oWebBrowser.Url.AbsoluteUri);
Process.Start(post);
}
catch
{
MessageBox.Show("ERRO");
}
}
When executing it does not display any MessageBox
and opens my browser on the page defined in Web Browser
(meulink
- to which has the form). Can anyone give me a help? I don’t know how to do this right, I’m basing myself on research.
that address
meulink
It’s some page, likewww.google.com
or is it a page of your application? It can be accessed without your system?– Richard Dias
It’s a regular forum page made up of
php
, can be accessed without my system. It would be a login screen and another post screen of a forum and this system will only be to streamline the posts.– Leonardo