How to set value in a Textarea field using webbrowser?

Asked

Viewed 183 times

0

I am trying to set a value in a Textarea type field using webbrowser, but it is not being set the value.

I’ve tried it like this;

webBrowser.Document.GetElementsByTagName("p")[2].InnerHtml = texto;
webBrowser.Document.GetElementsByTagName("p")[2].InnerText = texto;
webBrowser.Document.GetElementsByTagName("p")[2].SetAttribute("value", texto);

none worked.

In html it looks like this.

<div class="panel-body">
<label for="formGroupExampleInput">Coloque o texto acima no Textarea abaixo:</label>    
        <p><textarea class="form-control" rows="7"> </textarea></p>
<p>&nbsp;</p>
<p style="text-align:right;">
    <input type="submit" id="Submit" name="Submit" value="Próxima Tarefa" class="btn btn-primary" onclick="nextStep();">
</p>
</div>

is in the.

<p><textarea class="form-control" rows="7"> </textarea></p>

That the text should be set.

public void Stap3()
{
    HtmlDocument doc = webBrowser.Document;
    if (load)
    {
        load = false;
        webBrowser.Navigate("http://indigo.rafson.com.br/02.php");
        while (webBrowser.ReadyState != WebBrowserReadyState.Complete && webBrowser.Document == null)
        {
            Application.DoEvents();
        }
        doc = webBrowser.Document.Window.Open("http://indigo.rafson.com.br/02.php", "", "", false).Document;
    }

    int x = 0;
    while (x == 0)
    {
        Application.DoEvents();
        if (doc.GetElementsByTagName("p") != null &&
            doc.GetElementById("submit") != null)
            break;
    }

    String texto = string.Empty;
    foreach (HtmlWindow frame in doc.Window.Frames)
    {
        texto = frame.Document.GetElementsByTagName("p")[0].InnerHtml;
        texto += ";" + frame.Document.GetElementsByTagName("cite")[0].InnerHtml;
    }

    if (!string.IsNullOrEmpty(texto))
    {

        webBrowser.Document.GetElementsByTagName("p")[2].SetAttribute("value", texto);

        HtmlElement submit = doc.GetElementById("submit");
        submit.InvokeMember("click");
        NextStap = Stap4;
    }
    else
    {
        NextStap = Stap3;
    }
}

The complete solution is here.

inserir a descrição da imagem aqui

  • tries to define the element’s Innertext

  • had tried it, already this in the question .

  • you used tagname "p", try webBrowser.Document.GetElementsByTagName("textarea")

  • I tried so, but apparently not updating in the browser.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.