hola estoy tratando de agregar texto en un webbrowser con esto
WebBrowser1.Document.GetElementById("B").InnerText = "halo"
y este es el html
<body id="B" style="padding: 0px; margin: 2px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; background: rgb(255, 255, 255);>halo</body>
en el codigo html donde dice halo asi es como tendria que quedar pero no me funciona por que no agrega el texto alguien sabe como solucionar esto? :huh:
¿Te has dado cuenta que en el html que has mostrado NO has encerrado el style de CSS con comillas dobles?, no se si ha sido un error de edición por tu parte al publicar el código, o si ese es el mismo html original de la página, entonces esa podría ser la causa del problema, ya que con este error de sintaxis yo tampoco consigo reconocer correctamente el elemento:
Citar...255);>halo...
Ejemplo funcional:
Private Sub HtmlTest()
Dim htmlText As String =
<a><![CDATA[
<body id="B"
style="padding: 0px;
margin: 2px;
color: rgb(0, 0, 0);
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 15px;
background: rgb(255, 255, 255);">
This is a test inner text
</body>
]]></a>.Value
Dim htmlElement As HtmlElement
Dim wb As New WebBrowser With
{
.Dock = DockStyle.Fill,
.DocumentText = String.Empty
}
Me.Controls.Add(wb)
wb.Document.Write(htmlText)
htmlElement = wb.Document.GetElementById("B")
Select Case htmlElement Is Nothing
Case False
htmlElement.InnerText = "halooooo???"
Debug.WriteLine(htmlElement.OuterHtml)
Case Else
Throw New NullReferenceException("Element not found")
End Select
End Sub
Saludos
me funciono muy bien el codigo amigo gracias :)