0
我在通過Web Browser
向表單發送值時出現問題。我的目標是發佈一個帖子,或者send
這些inputsdo表單的值,並且submit
與在我的browser
中打開生成的頁面後相同。使用WebBrowser處理頁面
表:
<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">Default</option>
<option value="thumbup">OK</option>
<option value="thumbdown">Down</option>
<option value="exclamation">Exclamation</option>
<option value="question">question</option>
<option value="lamp">lamp</option>
<option value="smiley">smiley</option>
<option value="angry">angry</option>
<option value="cheesy">cheesy</option>
<option value="grin">grin</option>
<option value="sad">sad</option>
<option value="wink">wink</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="Send" tabindex="3" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit" />
</form>
C#:
WebBrowser oWebBrowser = new WebBrowser();
oWebBrowser.ScriptErrorsSuppressed = true;
oWebBrowser.Navigate("myLinkinInternet");
//button to posting
private void post_Click(object sender, EventArgs e)
{
try
{
HtmlElement subject = oWebBrowser.Document.GetElementsByTagName("input")["subject"];
if(subject != null)
{ //attempt to set the subject
subject.SetAttribute("value", subj);
MessageBox.Show("subj");
}
HtmlElement ico = oWebBrowser.Document.GetElementById("icon");
if (ico != null)
{ //attempt to set the icon
ico.SetAttribute("value", m.traduzIcon(icon.Text));
MessageBox.Show("icon");
}
HtmlElement message = oWebBrowser.Document.GetElementById("message");
if (message != null)
{ //attempt to set the message
message.InnerText = default;
MessageBox.Show("default");
}
HtmlElement form = oWebBrowser.Document.GetElementById("postmodify");
if (form != null)
{ //attempt to submit
form.InvokeMember("submit");
MessageBox.Show("submit");
}
//attempt to open the link poster
ProcessStartInfo post = new ProcessStartInfo(oWebBrowser.Url.AbsoluteUri);
Process.Start(post);
}
catch
{
MessageBox.Show("ERRO");
}
}
當運行不顯示任何MessageBox
並打開Web Browser
定義我的瀏覽器頁面(myLinkInInternet
- 一個與表單) 。任何人都可以給我一個幫助嗎?我不知道該怎麼做,我正在研究。