I have a button on a webpage with the following inspection:
<button type="button" class="odd-item-dropdown-confirm" data-qa="button-odd-item-dropdown-confirm">Confirm</button>
I would like to click on this button, I tried:
function clickConfirm(){
var bntConfirm = document.querySelector('.btn.button-odd-item-dropdown-confirm');
bntConfirm.click();
}
clickConfirm();
And got Uncaught TypeError: Cannot read property 'click' of null
btnandbutton-odd-item-dropdown-confirmand sodocument.querySelector('.btn.button-odd-item-dropdown-confirm')is not finding the targetted button element that you are expecting. There isodd-item-dropdown-confirmonly, and querySelector doesn't track whatever there is insidedata-qaattribute like you've written.