Javascript. I’m trying to make script with tampermonkey, but nothing work with modal window

My problem is that the script clicks the button -> the button causes a modal window -> after that I try to click the button with the script in the modal window (modal body), but nothing happens
My script should click on button inside modal window (after button click, modal window should disappear)

// @require     https://greasyfork.org/scripts/12228/code/setMutationHandler.js
(function() {
var elems = document.getElementsByClassName("btn btn-default btn-block js-lot-raise"); 
           elems[0].click(); // here I press button to cause modal window


// maybe the elements are already on the page
checkThem([].slice.call(document.querySelectorAll('input[type="checkbox"]'))); 

// but anyway set a MutationObserver handler for them
setMutationHandler(document, 'input[type="checkbox"]', checkThem);

function checkThem(nodes) {
    nodes.forEach(function(n) { n.checked = true }); // check true all checkboxes (idk, but it check inside modal window)
}
    
 var elemss = document.getElementsByClassName('btn btn-primary btn-block js-lot-raise-ex'); //here i try to find button inside modal window, but nothing happens

    elemss[0].click(); // nothing
function foo () {location.reload();
}
setTimeout(foo, 300000);

})();```