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

Java Development

Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Need help to get attribute value of webpage via javascript in BrowserField



I am trying to capture the attribute values of input element of webpage in browserfield, throught injecting the javascript. On documentUnloading(BrowserField browserField, Document document) method am injecting a script and trying to get the value of attribute but am getting the "valuewrapper" exception. please let me know where going wrong.


Here is my code snippet:


class BrowserFieldScreen extends MainScreen 
    private BrowserField _bf;
    private BrowserFieldConfig _bfConfig;
    private String script;
        _bfConfig = new BrowserFieldConfig();        
        _bfConfig.setProperty( BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE );
        _bfConfig.setProperty( BrowserFieldConfig.ENABLE_COOKIES, Boolean.TRUE );
        script = "javascript:document.getElementById('Email').value";
        _bf = new BrowserField(_bfConfig);
        _bf.addListener( listener ); 
    private BrowserFieldListener listener = new BrowserFieldListener()
        public void documentAborted(BrowserField browserField, Document document)
            sendMessage("Aborted " + document.getDocumentURI());     
        public void documentCreated(BrowserField browserField, ScriptEngine scriptEngine, Document document)
           sendMessage("Created document "
            + document.getDocumentURI() + " with engine "
            + scriptEngine);    
        public void documentError(BrowserField browserField, Document document)
            sendMessage("Error in " + document.getDocumentURI());
        public void documentLoaded(BrowserField browserField, Document document)
            sendMessage("Loaded " + document.getDocumentURI());
        public void documentUnloading(BrowserField browserField, Document document)
            sendMessage("Unloading "+ document.getDocumentURI());
            ScriptEngine se =_bf.getScriptEngine();
            //Object retVal = (Object) se.executeCompiledScript(se.compileScript(script), null);  
            Object retVal = (Object) se.executeScript(script, this);
            String str = (String) retVal.toString();
        public void downloadProgress(BrowserField browserField, ContentReadEvent event)
            sendMessage("Downloaded " + event.getItemsRead()
            + " of " + event.getItemsToRead()); 
   public void sendMessage(String mssg) 
        final String errMssg = mssg;
        UiApplication.getUiApplication().invokeAndWait(new Runnable() {
            public void run() {                 

 I have also tried by parsing the document object of webpage return by documentUnloading(BrowserField browserField, Document document) method to get the entered value in textbox field of username of loaded page in browerfield

the snippet of loaded page source


<input type="text" name="Email"  id="Email" size="18" value="" class="gaia le val"/> 

am able to get the other attribute values of input element using dom parsing except "value" attribute it returns black string i.e. "". Another strange thing in debugging i can see the input element contains the value for attribute "value".



please help me on this issue.