Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Calling JavaScript method from HtmlUnit

user2476925Jul 27 2013

I need to traverse to another page for which I need to click on an anchor tag. On click of which the JS method gets executed and returns the page URL. However when make us of the following code the result is null. when I try to use the standard click() function I get Null.Snippet:

JS Function:

{code}

<script language="javascript">

    function doSubmit(QS)

{

var strLink ="https://www.hudhomestore.com/pages/FilterBlank.aspx?caseNumber=" + QS + "&redir=PropertySummary&sLanguage=ENGLISH&zipCode=&city=&county=&sState=AK&fromPrice=0&toPrice=0&fCaseNumber=&bed=0&bath=0&street=&buyerType=0&specialProgram=&Status=0&OrderbyName=SCASENUMBER&OrderbyValue=ASC&sPageSize=10&pageId=1"

top.location.href = strLink;

}

{code}

Java Code:
{code}

if(anchor1.getTagName().equals("a"))

                                {          

                                    String js = anchor1.getAttribute("onClick");

                                    System.out.println("Anchor is " + js);

                              

                                    ScriptResult result = page1.executeJavaScript("javascript:" + anchor1.getAttribute("onClick"));

                                

                                    if(result != null)

                                    {

                                        System.out.println("Result Aint Null" + result.toString());                                    

                                        Object jsResult = result.getJavaScriptResult();

                                    

                                        if(jsResult != null)

                                         {

                                            System.out.println("Result: " + jsResult);

                                        }

                                    }                                

                                }      

{/code}

Please help me.

Regards

Nitin

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 24 2013
Added on Jul 27 2013
0 comments
738 views