简体   繁体   中英

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. 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.

Assume a code simple as $("#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. To test (from a Bookmarklet):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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