1

looked through the 'net, as well as other replies on here..

i've got something that looks like the following html:

var langId = '-1';
var demoKey = 'null';
var extraParams = 'null'; // only used for User Registration page
var multiSelect = false;

and

function onCampusSelect_USA() {
    if($('campusUSAIdSelect').value == ''){clearAJAXTimer();hideLayer("programUSADiv");   hideLayer("errorDiv");    hideLayer("buttonDivUS"); return; }
    // REMOVE THIS LATER
    clearAJAXTimer();
    getData(buildParms('PROGRAMSUS','US','campusId='+$('campusUSAIdSelect').value + "&institutionId=" +  $('institutionUSAIdSelect').value));
}

i've tried the following with no luck

WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3);
webClient.setJavaScriptEnabled(true);
HtmlPage page = webClient.getPage("http://www.foo.com/");
ScriptResult scriptResult = page.executeJavaScript("${'multiSelect'}");
System.out.println(scriptResult.getJavaScriptResult());

so.. i'm trying to figure out just what should go in the execute line..

ScriptResult scriptResult = page.executeJavaScript( what goes here?? );

something like

document.mutliSelect.value() <<<< (which doesn;t work by the way..)

thanks

tom smith
  • 1,035
  • 7
  • 23
  • 39
  • In the API of the HtmlUnit you can find the answer to your question about "what goes here???" http://htmlunit.sourceforge.net/apidocs/com/gargoylesoftware/htmlunit/html/HtmlPage.html#executeJavaScript(java.lang.String). Depending on your requirement, the sourceCode can vary. I assume you try to get the value of the multiSelect node. The question is, how your html looks like, and not JavaScript and in which way you can identify your multiSelect node (for example: by knowing it's id, knowing it's name or maybe css class). Tell more about requirements and place some html – nemisj Feb 01 '10 at 16:30

1 Answers1

2

type the following into your browser navigation bar:

javascript:alert("hello!")

Using this technique, you can execute JavaScript commands. For HtmlUnit, replace "what goes here??" by the stuff you would type into the navigation bar without the "javascript:" part.

James Kingsbery
  • 7,298
  • 2
  • 38
  • 67