Hi, I am using Netbeans to write this program. I have this .java page that gets the url of the HtmlPage from the .properties page. And when this page is opened in the browser, there are drop down lists that have values I want to get from the user when he/she has selected, and save it to a database. I'm actually using mozilla firefox to open this page, and using firebug to inspect the drop down list element.
I know getElementById is a javascript code, however, my friend told me to use it in the .java page. This is how part of my code looks like. What I'm not sure is how to implement getElementById() and where.
HtmlPage pageMain =EBPage; WebRequest postRequestSettings = new WebRequest( new URL(getProperties("trustAdmin")), HttpMethod.POST); // Set the request parameters postRequestSettings.setRequestParameters(new ArrayList()); postRequestSettings.getRequestParameters().add(new NameValuePair("component", "edit")); postRequestSettings.getRequestParameters().add(new NameValuePair("formids", "unixTime,instance,time,description,message")); postRequestSettings.getRequestParameters().add(new NameValuePair("page", "Status")); postRequestSettings.getRequestParameters().add(new NameValuePair("service", "direct")); postRequestSettings.getRequestParameters().add(new NameValuePair("session", "T")); postRequestSettings.getRequestParameters().add(new NameValuePair("submitmode", "submit")); postRequestSettings.getRequestParameters().add(new NameValuePair("submitname", "")); // Insert instance of message here postRequestSettings.getRequestParameters().add(new NameValuePair("instance", instance)); // Insert content of message here postRequestSettings.getRequestParameters().add(new NameValuePair("message", message)); // Insert description of message here postRequestSettings.getRequestParameters().add(new NameValuePair("description", description)); // Insert time of message here postRequestSettings.getRequestParameters().add(new NameValuePair("time", time)); // Convert time to unix seconds postRequestSettings.getRequestParameters().add(new NameValuePair("unixTime", String.valueOf(System.currentTimeMillis() / 1000))); HtmlPage newPage1 = pageMain.getWebClient().getPage(postRequestSettings); WebRequest requestSettings = new WebRequest( new URL("http://www.google.com"), HttpMethod.GET); requestSettings.setRequestParameters(new ArrayList()); requestSettings.getRequestParameters().add(new NameValuePair("page", "Preview")); requestSettings.getRequestParameters().add(new NameValuePair("service", "page")); newPage1 = newPage1.getWebClient().getPage(requestSettings);
And I'm told to insert page.getElementById() in the place shown below:
HtmlPage page = null; page.getElementById() try { // Login proxy page = (HtmlPage) jsonBrowser.getPage(getProperties("jsonBrowser")); String proxyUrl = page.getForms().get(0).getAttribute("action"); System.out.println("Proxy Url" + proxyUrl); WebRequest requestSettings = new WebRequest( new URL(proxyUrl), HttpMethod.POST); requestSettings.setRequestParameters(new ArrayList()); requestSettings.getRequestParameters().add(new NameValuePair("PROXY_SG_PASSWORD", password)); requestSettings.getRequestParameters().add(new NameValuePair("PROXY_SG_PRIVATE_CHALLENGE_STATE", "")); requestSettings.getRequestParameters().add(new NameValuePair("PROXY_SG_REQUEST_ID", "")); requestSettings.getRequestParameters().add(new NameValuePair("PROXY_SG_USERNAME", userID)); // Get the page page = page.getWebClient().getPage(requestSettings); Logger.getLogger(postTrustMessage.class.getName()).log(Level.INFO, "===================================Login in Trust"); Logger.getLogger(postTrustMessage.class.getName()).log(Level.INFO, page.getWebResponse().getContentAsString()); } catch (IOException ex) { Logger.getLogger(postTrustMessage.class.getName()).log(Level.SEVERE, null, ex); } catch (FailingHttpStatusCodeException ex) { Logger.getLogger(postTrustMessage.class.getName()).log(Level.SEVERE, null, ex); } return page;
Any help would be greatly appreciated. Thanks.