I'm pretty sure this is impossible, but I need to make sure before I give up and go another route.
I have a page that is within an iframe and the menu is outside of it. I need to programmatically click on one of those menu items to make an action happens. The application is built weird so I'm trying to work with it and just make it work. I cannot make any html changes.
My html looks something like this.
<body>
<header>
<p><a id='menuItem'>Menu Item</a></p>
<p><a id='anotherMenuItem'>Another Menu Item</a></p>
</header>
<div id='mainContent'>
<iframe>
//Where all the content is and where the click will be happening.
</iframe>
</div>
</body>
and this is the click that needs to happen
$("#menuItem").click()
I've tried traversing to escape the iframe, but I have had no luck. I have also just tried calling the click, but there is no context so it has no idea what it's doing.
i have also tried this Access elements of parent window from iframe
But because of how this grabs elements it does not work with the click()
function. Or at least when I try I cannot get it to work
window.parent.document.getElementById('#menuItem').click()
I cannot even get a window.parent.document.getElementById('#menuItem').length
to find the element.