javascript - Uncaught ReferenceError: functionXXX is not defined at HTMLInputElement.onclick -


in selenium automation test, using remote webdriver , trying launch html file below. html page opens correctly, @ last part of code, trying click on submit button calls javascript function (actiondeterminator()). when button clicked call js function (actiondeterminator()), see error in console have mentioned @ bottom part.

below html:

string butnowbutton = "<!doctype html public -//w3c//dtd html 4.0 transitional//en>" +         "<html><head>" +         "<meta http-equiv='content-type' content='text/html'; charset='utf-8'>" +         "<meta content='mshtml 6.00.2900.3157' name='generator'></head>" +         "<body>" +         "<h1>hello it's testing page</h1>" +         "<hr>" +          "<p>enter following fields , press button initiate transaction" +         "transaction</p>" +         "<form name=sso action='' method='post'>" +         "<table border='1'>" +         "  <tbody>" +         "  <tr>" +         "    <td>name(*): </td>" +         "    <td><input title='name' value='adam' name='name'>" +         "  </td></tr>" +         "  <tr>" +         "    <th colspan='2'><input id='btnsubmit' onclick='return actiondeterminator();' type='submit' value='go content catalog' name='btnsubmit'>" +         "    </th></tr></tbody></table>" +         "    <input type=hidden value='https://someurl/' name='hook_url'>" +         "</form>" +         "<script type='text/javascript' name='javascript'>" +         "function actiondeterminator()" +         "{" +         "document.sso.action=document.sso.url.value+'/buyer/main/ad/somepath/directaction';" +         "alert('url ==>'+document.sso.action);" +         "document.sso.submit();" +          "}" +          "</script>" +          "<hr>" +         "</body></html>";   //below quick code use above html , launch page. //works fine, ( in sense, html page opened).    string htmldiv = "var div=document.createelement('div');div.innerhtml=\"" + butnowbutton + "\";arguments[0].appendchild(div);";  system.err.println("***" + htmldiv); //'dr' remote webdriver. webelement element = dr.findelementsbytagname("body").get(0);  dr.executescript(htmldiv, element);  //below code tries invoke function actiondeterminator(). dr.executescript("document.getelementbyid('btnsubmit').click();",""); 

and in console see below error:

data:,:1 uncaught referenceerror: actiondeterminator not defined     @ htmlinputelement.onclick (data:,:1)     @ <anonymous>:248:70     @ callfunction (<anonymous>:237:33)     @ <anonymous>:247:23     @ <anonymous>:248:3 onclick @ data:,:1 (anonymous) @ vm50:248 callfunction @ vm50:237 (anonymous) @ vm50:247 (anonymous) @ vm50:248 data:,:1 not allowed navigate top frame data url: data:, 

if use onclick event handler in dom, should put actiondeterminator function definition in <head> or window.onload event's callback.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -