ulixee / hero

The web browser built for scraping
MIT License
647 stars 32 forks source link

How to interact with elements in iframe? #250

Open tsung-sc opened 4 months ago

tsung-sc commented 4 months ago

there is a element in iframe,and i can find it by this code : "const iframe = await hero.getFrameEnvironment(hero.document.querySelector('iframe')); const targetElement= iframe.document.querySelector('xxx');"

but i can't interact with the element.so plz tell me how to do that?

blakebyrnes commented 4 months ago

Have you tried using a regular click/type on it? There are extension methods like $click and $contentDocument that make this somewhat easier too. (https://ulixee.org/docs/hero/basic-client/awaited-dom-extensions#content-document)

tsung-sc commented 4 months ago

i have try this way,but the cosole reported " Error: "Interaction.click" element isn't a click-able target.",i can click the target by use "iframe.document.querySelector('xxx').click()",but i can't use "iframe.document.querySelector('xxx').$click().Unluckily,the way i use "iframe.document.querySelector('xxx').click()" can't pass the robot check!

i have try this way,but the cosole reported " Error: "Interaction.click" element isn't a click-able target.",i can click the target by use "iframe.document.querySelector('xxx').click()",but i can't use "iframe.document.querySelector('xxx').$click().Unluckily,the way i use "iframe.document.querySelector('xxx').click()" can't pass the robot check!

blakebyrnes commented 4 months ago

We have elements in iframes that have tests that work. There could be something about this particular page that's throwing something off. If it is in a scrollable div, hero doesn't know how to click on it yet, unfortunately. You can click on an x/y position on the page too, so if you can figure out what it should be, you could try to just click the coordinates.

tsung-sc commented 4 months ago

We have elements in iframes that have tests that work. There could be something about this particular page that's throwing something off. If it is in a scrollable div, hero doesn't know how to click on it yet, unfortunately. You can click on an x/y position on the page too, so if you can figure out what it should be, you could try to just click the coordinates.

yeah,i find the solution by click x/y position

tsung-sc commented 4 months ago

one more question:hero core seems won't close the browser when client call hero.close().I found that the memory usage of the Core keeps increasing with increasing usage and does not decrease.I deploy a Core docker image in k8s,and client will call hero.close() when task done.

blakebyrnes commented 4 months ago

Good re:x/y. I introduced a bug in the last release that is fixed on the main-js branch but not in npm yet. There was just a comment on discord about working around it. Will try to get to npm soon.

tsung-sc commented 4 months ago

Good re:x/y. I introduced a bug in the last release that is fixed on the main-js branch but not in npm yet. There was just a comment on discord about working around it. Will try to get to npm soon.

tks a lot for this project,but plz fix this bug as soon as possible.now i have to restart my core image every day😂