I have been working on creating an automated Puppeteer script to download my monthly bank transactions from the bank's website.
However, I have encountered a strange error (refer to the attached Imgur link for images of this issue)
https://i.sstatic.net/suBnQ.jpg
Issue: querySelector Returns Null on Visible DOM Element:
See Screenshot: https://i.sstatic.net/XV2Ka.jpg
(1) The username input box is clearly visible on the website (), (2) However, when I execute
document.querySelector('#access-code')
, the console returns null.
I am curious about why this behavior is occurring and in what circumstances a browser would return null on a querySelector(#id) query
when the DOM element is clearly visible.
# EDIT: Strange Workaround that Resolves the Issue:
While experimenting further with the browser, I used DevTools to inspect the DOM element and copied the JS Path.
Interestingly, after using Chrome Devtools to copy the JS Path,
document.querySelector('#access-code')
returned the correct element.
Screenshot showing the correct element being returned: https://i.sstatic.net/suBnQ.jpg
In both instances, the same search string is used for document.querySelector
.