Tengo el siguiente HTML que se genera desde un servidor:
<button id="start-diag-suites" title="add new suite" tabindex="-1" class="css-wvwsyj"></button>¿Cómo hago clic en este botón con Javascript?
He intentado:
document.getElementById('start-diag-suites').click();y he probado el un poco más complejo:
element.dispatchEvent(new MouseEvent(eventName, { view: window, bubbles: true, cancelable: true, clientX: coordX, clientY: coordY, button: 0 })); }; var theButton = document.querySelector('#start-diag-suites'); if (theButton) { var box = theButton.getBoundingClientRect(), coordX = box.left + (box.right - box.left) / 2, coordY = box.top + (box.bottom - box.top) / 2; simulateMouseEvent (theButton, 'mousedown', coordX, coordY); simulateMouseEvent (theButton, 'mouseup', coordX, coordY); simulateMouseEvent (theButton, 'click', coordX, coordY); }``` but neither seem to work at all $('#start-diag-suites').click() const button = document.getElementById('start-diag-suites'); button.dispatchEvent(new Event('click'))