I have a button(hyperlink) with its equivalent HTML code as:
<span title="Enroll in Classes" class="SSSBUTTON_CONFIRMLINK">
<a class="SSSBUTTON_CONFIRMLINK" href="javascript:submitAction_win0(document.win0,'DERIVED_REGFRM1_LINK_ADD_ENRL$118$');" tabindex="202" ptlinktgt="pt_peoplecode" id="DERIVED_REGFRM1_LINK_ADD_ENRL$118$" name="DERIVED_REGFRM1_LINK_ADD_ENRL$118$">Proceed to Step 2 of 3</a>
</span>
I want to click the button 10 seconds after the page is loaded and I use the following code:
// ==UserScript==
// @name Add to cart
// @namespace Class
// @description Script to add to cart
// @include http://go.oasis.com/add/?STRM=2141
// @version 1
// @grant none
// ==/UserScript==
setInterval (clickOnProceedButton, 10 * 1000)
function clickOnProceedButton () {
var targSubmit = $("#DERIVED_REGFRM1_LINK_ADD_ENRL$118$");
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
targSubmit[0].dispatchEvent (clickEvent);
}
The above script is not working and does not click the button. Can someone point out what is wrong here, please?
EDIT: I get the following error in the Console
ERROR: Execution of script 'Add to cart' failed! Object [object global] has no method 'clickOnProceedButton'
TypeError: Object [object global] has no method 'clickOnProceedButton'
at Object.eval (unknown source)), 25:14)
at Object.eval (unknown source)), 27:4)
at ag (unknown source), 190:4)
at K (unknown source), 190:46)
at o (unknown source), 456:2)
at U (unknown source), 460:85)
at R (unknown source), 229:40)
Thanks in advance!