There is a webpage with a button on it, that downloads a picture. I want to programmatically download that picture by triggering the onclick event of the button. The only issue is, that the button itself is inside an iframe:
<iframe loading="lazy" src="https://some-domain.com/some-url">
<html>
...
<button id="myButton"></button>
</html>
</iframe>
All I want to do is trigger the onclick event. I've tried this using javascript, but every time I fail due to either:
- cross-site scripting issues while trying to get the content of the iframe,
- unable to get the button by ID or class because the iframe is lazy loaded.
Interestingly, if I inspect the element of the button with google dev tools, I can get a handle to the button by ID after that. But that requires the manual step of inspecting the element, and I want an automatic method.
Obviously, there has to be a way of doing this otherwise it would not be possible to click on the button at all with the browser. So how can I achieve this? How can I emulate the button click as if the user did it from the browser?