How to call javascript in HttpClient or Html Unit

I am using the HTTP POST method to perform certain actions on the website, for this it uses ajax connection javascript which creates the requestID ie var reqID = Math.floor(Math.random()*1000001);

to post. I want to access this reqID in order to perform an action. can anyone help me with regards to accessing java script in HttpClient? Or can we access a specific javascript reqID variable using HtmlUnit?

My JS includes:

ajaxConnection.prototype.execute = function() {
    var reqID = Math.floor(Math.random()*1000001);
    var params = "reqID=" + reqID ;
    for (var key in this.connection_parameters) {
        params += "&" + key + "=" + this.connection_parameters[key];
    }

      

and i call POST to do the ie action

String Src = PageSource_Post("http://www.example.com/ajax/ratingClient.php", new String[][]{{"reqID",""},{"id", "329602"},{"cmd", "rate"},{"rating", "2"},}, null);

      

for now I have saved the blank reqID and other parameters are obtained from sourceource!
I am trying with HtmlUnit also like

webClient.setJavaScriptEnabled(true);
HtmlPage firstPage = webClient.getPage("http://www.example.com/");
HTMLScriptElement script = new HTMLScriptElement();

      

From here I need to access a specific variable reqID

?

+3


source to share


2 answers


do you mean a web browser?

firebug for firefox and F12for IE



These tools will help you debug javascript, you have to switch the breakpoint in javascript codes and follow step by step to see your reqID value

0


source


It looks like you want to execute javascript from Java. Personally, I found HTMLUnit and the HTTPUnit javascript support is a bit lacking. We had similar problems and had great success using Selenium. You can create a quick test case using the Selenium IDE, which is a firefox plugin ( http://docs.seleniumhq.org/projects/ide/ ). It allows you to record your steps from Firefox and export your test case to a JUnit test. Here is a good link for steps. http://university.utest.com/selenium-basics-part-3-record-test-case-and-export-in-junit-format/



0


source







All Articles