I am trying to click a div whose class name is (xyz)
document.querySelector('.header-search-wrap').click();
<iframe src="https://www.gammerson.com" frameborder="0" width="500px" height="900px">
</iframe>
so I tried to run run below document.querySelector('.xyz').click(); but it gives me
error Uncaught TypeError: Cannot read property 'click' of null
but when I go to elements windows and search of XYZ class and then again go back to console window of chrome and run below code again
document.querySelector('.xyz').click();
surprisingly it works. I don't know what is the problem can any one help me solve the problem. I tried multiple time it only works when I open source code in elements window and then run the code.