From: Charu B. <cha...@gm...> - 2014-01-21 09:59:54
|
Hello, I am trying to click on a link on a website. I am able to isolate the anchor in the variable "selected". But I am unable to click on that anchor. Please advise how to click a anchor and get the resultant page. List anchors = ((HtmlPage)pageAfterLogin).getAnchors(); HtmlAnchor selected = null; for(int i = 0; i < anchors.size(); i++) { System.out.println(anchors.get(i)); if ( anchors.get(i).toString().contains("PasswordLink" )) { selected = (HtmlAnchor)anchors.get(i); } } System.out.println( " selected = " + selected ); *Page pageafterclick = selected.click();* // Getting the exception here. System.out.println("--------------------------------------------"); System.out.println(" *pageafterclick * = "); I am getting a huge Exception , part of that exception pasted below . -------------------------------------- [testng] ======= EXCEPTION START ======== [testng] EcmaError: lineNumber=[64] column=[0] lineSource=[null] name=[TypeError] sourceName=[ http://adc21.dummy.com:7036/abc/afr/partition/ie/n/default/opt/core-11.1.1.7.0-3309.js] message=[TypeError: Cannot find function createNode in object [object]. ( http://machinename.us.dummy.com:7036/abc/afr/partition/ie/n/default/opt/core-11.1.1.7.0-3309.js#64 )] [testng] com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function createNode in object [object]. ( http://machinename.us.dummy.com:7036/abc/afr/partition/ie/n/default/opt/core-11.1.1.7.0-3309.js#64 ) [testng] at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:526) [testng] at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:529) [testng] at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:536) [testng] at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:456) [testng] at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:925) [testng] at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:182) [testng] at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:200) [testng] at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:609) [testng] at com.gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:886) [testng] at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:529) [testng] at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:536) [testng] at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:891) [testng] at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1237) [testng] at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1208) [testng] at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1177) [testng] at dummy.oam.fiat.passwordpolicy.PasswordPolicy.accessResource(PasswordPolicy.java:687) [testng] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [testng] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [testng] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [testng] at java.lang.reflect.Method.invoke(Method.java:597) [testng] at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:76) [testng] at org.testng.internal.Invoker.invokeMethod(Invoker.java:673) . . . org.testng.SuiteRunner.run(SuiteRunner.java:223) [testng] at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) [testng] at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) [testng] at org.testng.TestNG.runSuitesSequentially(TestNG.java:1039) [testng] at org.testng.TestNG.runSuitesLocally(TestNG.java:964) [testng] at org.testng.TestNG.run(TestNG.java:900) [testng] at org.testng.TestNG.privateMain(TestNG.java:1182) [testng] at org.testng.TestNG.main(TestNG.java:1146) [testng] Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot find function createNode in object [object]. ( http://machinename.us.dummy.com:7036/abc/afr/partition/ie/n/default/opt/core-11.1.1.7.0-3309.js#64 ) [testng] at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3651) ------------------------------- Please advise how to click a anchor and get the resultant page. Thanks. |