简体   繁体   English

在Bookmarklet中触发点击事件最终在Asp.Net引发Null Reference异常的地方结束

[英]Firing click event in Bookmarklet ends up where Asp.Net throwing Null Reference exception

For testing purposes i have to fill certain inputs in a page and Submit it and validate the values, Since it is a repetitive task i have automated entering the inputs and Submitting it through a Simple JS file. 出于测试目的,我必须在页面中填写某些输入,然后提交并验证值,由于这是一项重复性任务,因此我已自动输入了输入并通过Simple JS文件提交。 The problem is i have to run it in Internet Explorer 9 where the script runs fine when i run it from the console, but when i convert it to a Bookmarklet the Click event generates an Null reference error. 问题是我必须在Internet Explorer 9中运行它,当我从控制台运行脚本时,脚本运行良好,但是当我将其转换为Bookmarklet时,Click事件会生成Null引用错误。

Assume a code simple as $("#sampleElement")[0].click(); 假设一个简单的代码为$("#sampleElement")[0].click(); The button is clicked and the corresponding event listener is fired when executed from the console but throws error when executed from a bookmarklet. 从控制台执行该按钮后,将单击该按钮并触发相应的事件侦听器,但从书签执行时将引发错误。

Make sure that jQuery is loaded and usable when the Bookmarklet code is executed, and also that the DOM is ready and complete. 确保在执行Bookmarklet代码时jQuery已加载并且可用,并且确保DOM准备就绪且完整。 To test (from a Bookmarklet): 测试(从书签):

if (typeof $ === 'undefined')
    alert('jQuery not available');
else if ($("#sampleElement").length === 0)
    alert('#sampleElement not available');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM