Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Contributor
Posts: 4
Registered: ‎10-07-2011
My Device: 9980
My Carrier: rogers

BrowserField2:executeScript("document.getElementById()") doesn't work

I have an element with id= testOnetapButton01 on the web page. and in BrowserFieldListener:documentLoaded I am able to get the element:

 

        Element testOnetapButton = document
                .getElementById("testOnetapButton01");

but when I tried to call BrowserField.executeScript("document.getElementById('testOnetapButton01')"), I got ExecuteScript Exception:

ExecuteScript Exception: TypeError: Result of expression 'window.document.getElementById("testOnetap[0.0] Button01")' [null] is not an object.

 

It's weired that the element id is changed([0.0] is inserted in the middle).

 

This is the event handler for documentLoaded:

 

public void documentLoaded(BrowserField browserField, Document document)
            throws Exception {
        if ((browserField != null) && (document != null)) {
            String title = browserField.getDocumentTitle();
            System.out.println("[" + this.getClass().getName() + "] Document '"
                    + title + "' loaded");
        }
        super.documentLoaded(browserField, document);
        Element testOnetapButton = document
                .getElementById("testOnetapButton01");
        if (testOnetapButton == null) {
            // browserField.executeScript("alert('did not get the button element')");
        } else {
            System.out
                    .println("!!!!!!!!!!!!!!!!!!!!!!!!DEBUG BLOCK START!!!!!!!!!!!!!!");
            String id = testOnetapButton.getAttribute("id");

            System.out
                    .println("Element id = " + id);
            try {
                // browserField.executeScript("alert('GOT the button element!')");
                final String script = "window.document.getElementById(\"testOnetapButton01\").click()";

                browserField.executeScript(script);
            } catch (Exception e) {

                System.out
                        .println("ExecuteScript Exception: " + e.getMessage());
                System.out
                        .println("!!!!!!!!!!!!!!!!!!!!!!!!!DEBUG BLOCK END!!!!!!!!!!!!!!!!");
                String msg = e.getMessage();
            }
        }
    }

 

What am I did wrong?

 

Thanks a lot.

Winter.