0

I need to type movie title in the search input and click on the "Search" button, then I need to wait for the page load and click on it I need to do it in Console of Browser Here is my code

document.getElementById('story').value='Troy';
document.querySelector('body > div.wrapper > div.header > div.header44 > div.search_panel > span > form > button').click();
document.addEventListener("DOMContentLoaded", () => {
document.getElementsByTagName('a')[1].click();
} );

If I do these steps separately, everything works. But I need to do it all at once (by one script) Here is the last action, waiting for the page load and clicking on it

document.addEventListener("DOMContentLoaded", () => {
document.getElementsByTagName('a')[1].click();
} );

I think this last action is triggered ahead of time how to write this code correctly?

0 Answers0