我试图触发具有以下来源的动态生成页面上的按钮:
<button class="pt-button" type="button">Restart</button>
我尝试了以下操作,但不起作用。有指针吗?
(function() {
'use strict';
waitForKeyElements("#button.pt-button:contains('Restart')", clickButtonAfterDelay);
function clickButtonAfterDelay (jNode) {
if (document.readyState != "complete") return true;
setTimeout (triggerMouseEvent, 2222, jNode[0], "click");
}
function triggerMouseEvent (jNode) {
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
jNode[0].dispatchEvent (clickEvent);
}
})();