#170 getAttribute function support in HTMLElement

closed
None
7
2008-04-15
2008-01-14
Anonymous
No

Add JS function getAttribute to the HTMLElement which returns value of the tag attribute by it name. GWT (http://code.google.com/webtoolkit/) is required this function and not working without it. My solution is here:

static public class HTMLElement extends JavaScriptEngine
....
public Object jsFunction_getAttribute(String attributeName) {
return _scriptable.get(attributeName);
}

....

Discussion

  • Wolfgang Fahl

    Wolfgang Fahl - 2008-03-31
    • priority: 5 --> 7
    • assigned_to: nobody --> wolfgang_fahl
    • status: open --> pending
     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-03-31

    Logged In: YES
    user_id=1220573
    Originator: NO

    If added two test cases for this both fail for the old scripting enging, the body one has a slight problem for the new scripting engine but the div one works.

    /**
    * test to access attributes from java script
    * @throws Exception
    */
    public void testGetAttributeForBody() throws Exception {
    if (HttpUnitOptions.DEFAULT_SCRIPT_ENGINE_FACTORY.equals(HttpUnitOptions.ORIGINAL_SCRIPTING_ENGINE_FACTORY)) {
    // TODO try making this work
    return;
    }

    defineWebPage( "OnCommand", "<html><head><title>test</title>\n"+
    "<script type='text/javascript'>\n"+
    "function show (attr) {\n"+
    // TODO make this work
    " var body=document.body;\n"+
    " //var body=document.getElementById('thebody');\n"+
    " alert(body.getAttribute(attr));\n"+
    "}\n"+
    "</script></head>\n"+
    "<body id='thebody' bgcolor='#FFFFCC' text='#E00000' link='#0000E0' alink='#000080' vlink='#000000'>\n"+
    "<a href=\"javascript:show('bgcolor')\">background color?</a><br>\n"+
    "<a href=\"javascript:show('text')\">text color?</a><br>\n"+
    "<a href=\"javascript:show('link')\">linkcolor non visited</a><br>\n"+
    "<a href=\"javascript:show('alink')\">link color activated links?</a>\n"+
    "<a href=\"javascript:show('vlink')\">link color non visited</a><br>\n"+
    "</body></html>");
    WebConversation wc = new WebConversation();
    WebResponse response=wc.getResponse( getHostPath() + "/OnCommand.html" );
    // the page for testing externally
    // System.err.println(response.getText());

    WebLink[] links=response.getLinks();
    for (int i=0;i<links.length;i++) {
    links[ i ].click();
    }
    String expected[]={
    "#FFFCC","#E0000","#000E0","#00080","#40000"
    };
    for (int i=0;i<links.length;i++) {
    assertEquals( "Message for link "+i, expected[i], wc.popNextAlert() );
    }
    }

    /**
    * test to access attributes from java script
    * @throws Exception
    */
    public void testGetAttributeForDiv() throws Exception {
    if (HttpUnitOptions.DEFAULT_SCRIPT_ENGINE_FACTORY.equals(HttpUnitOptions.ORIGINAL_SCRIPTING_ENGINE_FACTORY)) {
    // TODO try making this work
    return;
    }

    defineWebPage( "OnCommand", "<html><head><title>test</title>\n"+
    "<script type='text/javascript'>\n"+
    "function show (id,attr) {\n"+
    " var element=document.getElementById(id);\n"+
    " alert(element.getAttribute(attr));\n"+
    "}\n"+
    "</script></head>\n"+
    "<body> <div id='div1' align='left'>\n"+
    "<a href=\"javascript:show('div1','align')\">align attribute of div</a><br>\n"+
    "</div></body></html>");
    WebConversation wc = new WebConversation();
    WebResponse response=wc.getResponse( getHostPath() + "/OnCommand.html" );
    // the page for testing externally
    // System.err.println(response.getText());
    WebLink[] links=response.getLinks();
    for (int i=0;i<links.length;i++) {
    links[ i ].click();
    }
    String expected[]={
    "left"
    };
    for (int i=0;i<links.length;i++) {
    assertEquals( "Message for link "+i, expected[i], wc.popNextAlert() );
    }
    }

     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-03-31

    Logged In: YES
    user_id=1220573
    Originator: NO

    This feature is now in the subversion repository and will be included in the next release.

     
  • SourceForge Robot

    Logged In: YES
    user_id=1312539
    Originator: NO

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     
  • SourceForge Robot

    • status: pending --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks