-1

I am connecting to a website trough a webbrowser, then i want to post a message on a message board.

This is the HTML of the text box:

<div class="fr-element fr-view" dir="ltr" contenteditable="true" style="min-height: 100px;" aria-disabled="false" spellcheck="true"><p>TEXT GOES HERE</p></div>

I have tried the following 2 codes:

For Each CurrentElement As HtmlElement In WebBrowser1.Document.GetElementsByTagName("div")
    If CurrentElement.GetAttribute("class") = "fr-element fr-view" Then
        CurrentElement.InnerText = TextBox1.Text
    End If
Next

For Each CurrentElement As HtmlElement In WebBrowser1.Document.GetElementsByTagName("div")
    If CurrentElement.GetAttribute("class") = "fr-element fr-view" Then
       For Each InnerCurrentElement As HtmlElement In CurrentElement.GetElementsByTagName("p")
            InnerCurrentElement.InnerText = RichTextBox1.Text
       Next
    End If
Next

None of them does anything

I really havent even messed around with HTML before this at all even so I am not sure what I could search for to solve my issue as I am able to handle other text boxes, for example the login ones which are like this:

<input type="text" class="input" name="login" autofocus="autofocus" autocomplete="username" id="aaaaa">
SoLux
  • 162
  • 1
  • 9
  • `CurrentElement.GetAttribute("className")`. The document must be already loaded and the elements must belong to the current Document Frame. Html Documents may contain IFrames. Each IFrame has its own Document, not accessble from the main Document body. So, you first have to verify whether the `Frames` collection contains more than one frame. If that's the case, read the notes here: [How to get an HtmlElement value inside Frames/IFrames?](https://stackoverflow.com/a/53218064/7444103) – Jimi Nov 22 '19 at 18:59

1 Answers1

0

You must to do that after your WebBrowser have finished to load the document. A little example below:

    WebBrowser1.ScriptErrorsSuppressed = True
    WebBrowser1.Navigate("https://html.com/tags/input/")
    AddHandler WebBrowser1.DocumentCompleted, Sub(senderObj As Object, eObj As WebBrowserDocumentCompletedEventArgs)
                                                  Dim inputs As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
                                                  If inputs IsNot Nothing AndAlso inputs.Count > 0 Then
                                                      For Each current As HtmlElement In inputs
                                                          current.SetAttribute("value", "Eurekaaaaaaaaaaaaaaaaaaaaa")
                                                      Next

                                                  End If
                                              End Sub
G3nt_M3caj
  • 2,497
  • 1
  • 14
  • 16
  • I am already doing this trough the following code: https://pastebin.com/raw/qHs01cnq – SoLux Nov 22 '19 at 14:37
  • Give me your url you navigate on and which element you want to put text inside – G3nt_M3caj Nov 22 '19 at 14:39
  • Can't do that mate, I already provided the HTML for the textbox – SoLux Nov 22 '19 at 14:50
  • 1
    All’s right. However I think your issue is in attribute value comparison. Try this instead: 'If Strings.Replace(Trim(CurrentElement.GetAttribute("class")).ToLower, " ", "") = Strings.Replace("fr-element fr-view", " ", "") Then' – G3nt_M3caj Nov 22 '19 at 14:54
  • Damn bro that's really convoluded. I did try it however and it did not work. Is it supposed to be some sort of support in case the text in the HTML was a different size or contained other filler? – SoLux Nov 22 '19 at 14:58
  • In some cases you cannot have access on DOM elements if those is generated in runtime by javascript the only way to have access is by javascript. One try you can get is that you try to navigate on your url from a webbrowser (firefox or chrome) and take a look if you are able to find your element by developer options (F12) – G3nt_M3caj Nov 22 '19 at 15:06
  • well that's how I found it in the first place, the HTML that is. are you talking about something else? – SoLux Nov 22 '19 at 15:13
  • Without an url I can't help you :(. – G3nt_M3caj Nov 22 '19 at 15:20
  • https://xenforo.com/community/threads/show-older-items-prompt-not-showing.172536/ but you need an account in order to access the reply – SoLux Nov 22 '19 at 15:23
  • Do I have to register an account? – G3nt_M3caj Nov 22 '19 at 15:28