gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 04:12:34 31 4
gpt4 key购买 nike

在我的 selenium 自动化测试中,我正在使用远程 Webdriver 并尝试启动一个 html 文件,如下所示。 HTML 页面正确打开,但在代码的最后部分,我尝试单击调用 javascript 函数 (ActionDeterminator()) 的提交按钮。当单击该按钮来调用 js 函数 (ActionDeterminator()) 时,我会在控制台中看到一个错误,我在底部提到过。

下面是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 a testing page</H1>" +
"<HR>" +

"<P>Enter the following fields and press the button to 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 to 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 is ==>'+document.SSO.action);" +
"document.SSO.submit();" +

"}" +

"</SCRIPT>" +

"<HR>" +
"</BODY></HTML>";
//Below is the quick code to use above html and launch a page. This also //works fine, ( in the sense, html page is opened).

String htmlDiv = "var div=document.createElement('div');div.innerHTML=\"" + butNowButton + "\";arguments[0].appendChild(div);";

System.err.println("***" + htmlDiv);
//'dr' is basically remote webdriver.
WebElement element = dr.findElementsByTagName("BODY").get(0);

dr.executeScript(htmlDiv, element);

//below code tries to invoke function ActionDeterminator().
dr.executeScript("document.getElementById('btnSubmit').click();","");

在控制台中我看到以下错误:

data:,:1 Uncaught ReferenceError: ActionDeterminator is not defined
at HTMLInputElement.onclick (data:,:1)
at <anonymous>:248:70
at callFunction (<anonymous>:237:33)
at <anonymous>:247:23
at <anonymous>:248:3
onclick @ data:,:1
(anonymous) @ VM50:248
callFunction @ VM50:237
(anonymous) @ VM50:247
(anonymous) @ VM50:248
data:,:1 Not allowed to navigate top frame to data URL: data:,

最佳答案

如果您在 DOM 中使用 onclick 事件处理程序,则应该将 ActionDeterminator <head>中的函数定义或window.onload事件的回调。

关于javascript - Uncaught ReferenceError : functionXXX is not defined at HTMLInputElement. onclick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46140148/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com