Documentation‎ > ‎

Frequently Asked Questions

If you have a question about JExplorer and it is not listed in this FAQ, please send it to us using the support forum and we will add it here after answering to you.

Can I embed Internet Explorer into a Swing container? Can I use Internet Explorer without displaying any windows?

Yes, JExplorer provides both these capabilities. There are two classes: Browser (a Swing component) and HeadlessBrowser (a class for automated testing without GUI).

How to get source of the HTML document?

Load a page using HeadlessBrowser instance and get the HTML document source by calling the WebBrowser.getContent() method:
WebBrowser browser = new HeadlessBrowser();
browser.navigate("http://google.com");
// Wait until page is loaded completely browser.waitReady(); String content = browser.getContent();
System.out.println("Source of page: ");
System.out.println(content);
Attached files: CreateHeadlessBrowserSample.java

How to embed Internet Explorer into a Swing container?

Create a Browser component, add it into a Swing container:
Browser browser = new Browser();

JFrame frame = new JFrame("JExplorer - Create Browser Sample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.getContentPane().add(browser, BorderLayout.CENTER);
frame.setVisible(true);

// Wait when the browser will be ready to work browser.waitReady(); browser.navigate("http://google.com")


Attached files: CreateBrowserSample.java

How to get an element in the HTML document as a Java object?

The WebBrowser.getDocument() method returns org.w3c.dom.Document object that can be used for finding elements in a document. The code below searches for the submit button by name:

public void execute(){
...
Element searchButton = getSearchButton(browser.getDocument());
}
private static Element
getSearchButton(org.w3c.dom.Documentdocument){
org.w3c.dom.NodeListinputs = document.getElementsByTagName("input");
for(int i = 0;i < inputs.getLength();i++){
org.w3c.dom.Elementinput = (org.w3c.dom.Element)inputs.item(i);
Stringname = input.getAttribute("name");
if("btnG".equals(name))
return input;
}
return null;
}

Attached files: SubmitFormSample.java, DomNavigationSample.java

How to get/set attributes of an element?

Find the element in the document and then call the org.w3c.dom.Document.getAttribute() or setAttribute() methods:
Element login = browser.getDocument().getElementById("i1");
// Get an element attribute String type = login.getAttribute("type");
// Set an element attribute login.setAttribute("value","john");
Attached files:ElementAttributesSample.java

How to navigate to a link in the HTML document?

Find the link in the page and call the DomRobot.click() method:

Element groupsLink = browser.getDocument().getElementById("2a");
if(groupsLink != null){
DomRobot robot = newDomRobot(browser);
showMessage("Navigate Groups link");
robot.click(groupsLink);
}

Attached files: NavigateLinkSample.java

How to fill the form controls in an HTML document with specified values?

Find a control in a document, then set the "value" attribute for a text field, "checked" attribute for a checkbox, "selected" attribute for a radio button:
browser.navigate("http://google.com");
browser.waitReady();
// Find a text field in the page Element textInput = getTextInput(browser.getDocument()); textInput.setAttribute("value","JExplorer");

Attached files: SubmitFormSample.java

How to submit a form to the server?

Find a submit button of the form and click the button using the DomRobot.click() method:

Element searchButton = getSearchButton(browser.getDocument());
DomRobot robot = newDomRobot(browser);
robot.click(searchButton);

Attached files: SubmitFormSample.java

How to execute JavaScript code?

Use the Browser.executeScript(String) method:
// Get JavaScript counter variable
String counter = (String)browser.executeScript("counter");
...
// Set JavaScript counter variable browser.executeScript("counter = 7;");
Attached files: JavascriptSample.java

How to listen to events from the document elements in Java code?

Add an event listener to an element:
private void setupChangeListener(final org.w3c.dom.Element select){
org.w3c.dom.events.EventTarget eventTarget = (org.w3c.dom.events.EventTarget)select;
eventTarget.addEventListener("onchange",new EventListener(){
public void handleEvent(Eventevt){
            Element target = (Element)evt.getTarget();
            // Gets current value of selected target             String value = target.getAttribute("value");
showMessageSwingLoop("Selected product: "+value);
}
},false);
}

Is there any easy way to find the absolute screen position for a org.w3c.dom.html.HTMLElement ?

To obtain the absolute screen position of any org.w3c.dom.html.HTMLElement, you will need to cast an instance of such element to the HTMLElement interface from com.jniwrapper.win32.ie.dom package and then use its getAbsoluteLocation() method. For example:
HTMLElement htmlElement = (HTMLElement)element;
Point point = htmlElement.getAbsoluteLocation();

Which methods should I use instead of deprecated methods of the DomRobot class?

The HTMLElement interface contains element-specific methods and HTMLDocument interface contains document-specific methods. The WebBrowser.setSilent(boolean) method enables/disables the error, alert, and confirmation dialogs.

Are there any guiding principles to avoid deadlocks in the application that uses JExplorer?

Don't call the WebBrowser.waitReady() method from Swing or OLE message loop thread.

If I work with JExplorer through COM interfaces (native peer objects), I get ComException: COM object method returns error code: 0x80004005; E_FAIL. What's wrong?

You should work with peer objects in the OLE message loop of the browser. See the chapter " Working with Native Peers and Avoiding Thread Issues" inside JExplorer Programmer's Guide. Otherwise, please refer to the corresponding interface's documentation in MSDN to get know method specific meaning of the error code.

When the browser component is visible all of my menus and tooltips seem to show under the browser panel. Can this be fixed?

To solve this problem, just add the following code to appropriate place in your application:

static
{
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
}

I get the following error: ciceroUIWNDFRAME: javaw.exe - apllication error[new]

This error is not caused by JNIWrapper, but rather by Microsoft Office's Speech and Handwriting Recognition. In order to continue using JNIWrapper, you will need to disable this Microsoft feature. To disable the Speech and Handwriting Recognition:
  • Click "Start" button at the bottom left of Microsoft Windows.
  • Click "Control Panel."
  • Click "Add/Remove Programs."
  • Click "Microsoft Office."
  • Click on the "Change" button
  • Browse to "Office Shared Features."
  • Click on "Alternative User Input."
  • For both the Speech and Handwriting Recognition, select "Not available."
Once this is disabled, the CiceroUIWndFrame messages disappear. Also, please check this Microsoft support site for a more detailed set of steps to remove these tools: http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;326526.
ċ
Unknown user,
May 3, 2012, 3:02 AM
ċ
Unknown user,
May 3, 2012, 3:00 AM
ċ
Unknown user,
May 3, 2012, 3:07 AM
ċ
Unknown user,
May 3, 2012, 3:07 AM
ċ
Unknown user,
May 3, 2012, 3:07 AM
ċ
Unknown user,
May 3, 2012, 3:07 AM
ċ
Unknown user,
May 3, 2012, 3:07 AM