I'm having trouble sending values to a form via Web Browser
. My goal is to make a post, that is, send the values to the inputs
of the form and make the submit
of it, after that 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 running it does not display any MessageBox
and opens my browser on the page defined in Web Browser
( meulink
- the one that has the form). Can someone give me a help? I do not know how to do this right, I'm relying on surveys.