|
There are a number of ways in which you can interact with a web page using OpenSpan’s integration technologies. Most commonly, you would use the adapter’s properties, methods, and events like you do with any other .Net class.
However sometimes you need to dig a bit deeper into the webpage. One instance is when a web page is using Jscript to perform operations that you need to modify or block.
The attached solution has a simple web page that has a couple of controls on it. The web page is hosted on OpenSpan’s website for you to test against.
The demo solution has a WinForm that allows you to operate the web page but from a separate application. You can cause the web page menu to open or close and also cause text to be copied to it and an emulated search started.

When you start the solution, the WinForm is first created and it in turns starts the web adapter. Likewise, when you exit the winform application, it will close the browser. This is done by handling the Form_load and Form_Closing events from .Net as follows:
/// Start adapters when the form is initially loaded. private void Form1_Load( object sender, EventArgs e ) { if ( m_DHTMLSample.IsRunning == false ) { m_DHTMLSample.Start(); } }
/// Stop adapters when the form is closing. private void Form1_FormClosing( object sender, FormClosingEventArgs e ) { if ( m_DHTMLSample.IsRunning ) { m_DHTMLSample.Stop(); } }
The webpage needs to be interrogated and then the webpage control is perform functions on the embedded controls of the page. The OpenSpan webpage control (named Dropdown_Sample below) has a method called ExecuteScript() with which the code can pass jscript to the browser and have it executed.
Below shows the web page with the main menu already opened.

The controls on the web page won’t be used in this example except for the webpage control which has the ExecuteScript() method that we’ll use.

There are a couple of examples of what can be done in the example but how they are done is the same in each case. First, a jscript routine is written to perform a function, in this case to emulate a mouseOver event. The jscript code is:
var menuObject = document.getElementById('sample_attach_menu_parent'); if(menuObject != null && menuObject != 'undefined') { menuObject.onmouseover(); }
The jscript is placed in a string and passed to the ExecuteScript method as below.
private void openMenu_Click( object sender, EventArgs e ) { // Script to open the menu items. string jScript = "var menuObject = document.getElementById('sample_attach_menu_parent');" + "if ( menuObject != null && menuObject != 'undefined') menuObject.onmouseover();";
// Execute script defined above m_DHTMLSample.Dropdown_Sample.ExecuteScript( jScript, "JavaScript" ); }
|