Is it possible in VB.net’s Geckofx to use `Getelementbyid`?

Asked

Viewed 154 times

-1

It is possible in VB.net’s Geckofx to use the GetelementByID? I made some attempts with the code using google.com:

geckowebbrowser1.document.getelementbyid("lst-ib").setattribute("value", "teste")

but it’s returning me: "Object reference not set to an object instance." Gecko.GeckoDomDocument.Getelementbyid(...) returned Nothing

I’ve been doing some research and I haven’t found.

  • It would be nice if you asked the question better. Read the https://answall.com/help/mcve for a better idea

1 answer

0

Other than WebBrowser, is another procedure to get the ID of an element in HTML. Consider this small code your page and its element:

<div id="lst-ib">conteúdo</div>

In the Gecko API, you need to create an instance of a GeckoHtmlElement, thus will not cause null references, as in your error.

Dim elemento As GeckoHtmlElement
ele = geckowebbrowser1.Document.GetHtmlElementById("lst-ib")
If(ele Is Nothing) MsgBox("Não foi possível encontrar um elemento com esse ID.")
ele.setAttribute("value", "teste")

setAttribute(string, string)

Source of the answer

  • Thank you for your reply, but I could not use the example you told me. I continue with the same null return. "Undefined object reference for an instance of an object."

  • Strange. You can make clear the line that the error happens?

  • Private Sub btnenviar_Click(Sender As Object, and As Eventargs) Handles btnenviar.Click Dim he As Gecko.Geckohtmlelement he = wb01.Document.Gethtmlelementbyid("lst-Ib") he.Setattribute("value", "test")"by inserting me in this row returns me Object reference not defined for an instance of an object." End Sub sorry I couldn’t format the Script on the page

  • I reworked the answer with a "clue". Try to run now and update me here.

  • in google, ran Msgbox and did not insert giving the same error. , plus a small question!!

  • it is possible to insert data using Getelementsbyclassname ?

  • I couldn’t find any documentation on GetElementsByClassName. See your statement and if there are methods for entering data in the function.

Show 2 more comments

Browser other questions tagged

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