Change textarea inside webbrowser

时间:2015-11-12 11:13:24

标签: vb.net visual-studio browser

I'm trying for hours to change a text area inside a webbrowser in VB.net. I was not able to do it... This is the code from that textarea :

<textarea name="message_html" class="textCtrl MessageEditor BbCodeWysiwygEditor " id="ctrl_message_html" style="height: 260px; display: none;" data-options='{"autoSaveFrequency":"60","bbCodes":[]}' data-auto-save-url="forums/Snapchat-Girls/save-draft" data-dialog-url="index.php?editor/dialog&amp;style=1" data-css-url="css.php?style=1&amp;css=editor_contents&amp;d=1447310869">&lt;p&gt;This is where the text will be&lt;/p&gt;</textarea>

Note : Loog for "This is where the text will be" inside the code.

Codes i tried :

    For Each element As HtmlElement In Me.WebBrowser1.Document.All
        If element.OuterHtml.Contains("textCtrl MessageEditor") Then
            element.SetAttribute("value", "TEST")
        End If
    Next

   WebBrowser1.Document.GetElementById("ctrl_message_html").SetAttribute("value","TEST")

    For Each element As HtmlElement In Me.WebBrowser1.Document.All
         element.SetAttribute("value", "TEST")
    Next

None of these worked...

PS : Is not my website. So don't ask me to add ids or something.

1 个答案:

答案 0 :(得分:0)

我相信这不再需要了,但是可以参考那些可能仍在寻找这个问题答案的人....也许这可能有助于你的需求

Dim Wctl as string = WebBrowser1.DocumentText.Replace(&#34; [searchvalue1]&#34;,&#34; test1&#34;)。替换(&#34; [searchvalue2]&#34;, &#34; TEST2&#34)

然后

WebBrowser1.DocumentText =&#34; 0&#34;
WebBrowser1.Document.OpenNew(True)
WebBrowser1.Document.Write(Wctl)
WebBrowser1.Refresh()