0
votes

I am using C++Builder XE4-pro with the VCL 32bit platform. I am using the component named CppWebBrowser to load a JPL web page. I added a picture of the web page below. The code below is my button event that loads the web page. The web page is used by manually entering an asteroid name into the search box and pressing the enter key. This runs a script that loads the asteroid details. I need to run the search box using code. One sample asteroid name is Eros. Is there any way to activate this search box for Eros using code?

void __fastcall TForm1::Button1Click(TObject *Sender)
{
UnicodeString Full;
Full = "https://ssd.jpl.nasa.gov/sbdb.cgi#top";
CppWebBrowser1->Navigate( Full.c_str() );
}

JPL Web Site

1

1 Answers

2
votes

After the page has been fully loaded (the OnDocumentComplete event has been fired), you can use the browser's own DOM interfaces to find and fill in the search box, and then submit its containing form.

Start by querying the Document property for the IHTMLDocument2 interface, and go from there.

IHTMLDocument2 has a forms collection you can use to enumerate the <form> elements on the page, enumerating each form's <input> elements using the IHTMLDocument3::item() method until you find the <input> element of the desired search box. Or, you can query the Document for IHTMLDocument3 and use its getElementById() or GetElementsByName() method to find the desired search box directly.

When you have found the search element, you can query it for IHTMLInputElement, set its value property to whatever text you want, and then call its containing form's submit() method.