Closed Fragaile closed 11 months ago
are you sure the found elements are iframes? Also, please provide the relevant HTML
Thanks for replying,
I'm not looking for elements, I just want to switch to the iframe, like I said, it works in selenium. I don't know what kind of html you want me to provide but here's the iframe I'm trying to switch to.
HTML:
<span data-cse="encryptedSecurityCode" data-uid="adyen-checkout-encryptedSecurityCode-XXXX" class="adyen-checkout__input adyen-checkout__input--small adyen-checkout__card__cvc__input CardInput-module_adyen-checkout__input__11tlB">
<iframe src="https://checkoutshopper-live.adyen.com/checkoutshopper/securedfields/live_XXXXXXXXXXXXXX/4.5.0/securedFields.html?type=card&d=XXXXXXXXXXXXXXX=" class="js-iframe" title="Iframe for security code" allowtransparency="true" style="border: none; height:100%; width:100%; overflow:hidden;" referrerpolicy="origin">
<p>Your browser does not support iframes.</p>
</iframe>
</span>
@Fragaile
can you provide what await iframes[0].source
gives you? Also, as long you f don't provide the full relevant HTML, I can't reproduce this.
@kaliiiiiiiiii print(iframes[0].source)
gives me:
<iframe src="https://checkoutshopper-live.adyen.com/checkoutshopper/securedfields/live_XXXXXXXX/4.5.0/securedFields.html?type=card&d=XXXXXXXX=" class="js-iframe" title="Iframe for security code" allowtransparency="true" style="border: none; height:100%; width:100%; overflow:hidden;" referrerpolicy="origin">
<p>Your browser does not support iframes.</p>
</iframe>
The 'XXXXX' areas are just blanked out by me, not relevant info.
Do you want me to provide the entire page source html? I'm pretty sure it would be broken, but I'll try.
@Fragaile Huh thanks, this actually seems to be a bug. I'll do some testing. Thanks for opening this issue btw!
@kaliiiiiiiiii No problem, thank you too 💯
@Fragaile
dev
version as well? ( install with pip install https://github.com/kaliiiiiiiiii/Selenium-Driverless/archive/refs/heads/dev.zip
)
import asyncio
from selenium_driverless import webdriver from selenium_driverless.types.by import By from selenium_driverless.types.webelement import NoSuchElementException
async def main(): options = webdriver.ChromeOptions()
async with webdriver.Chrome(options=options) as driver:
await driver.get("https://nopecha.com/demo/turnstile")
await asyncio.sleep(0.5)
# some random mouse-movements over iframes
pointer = await driver.current_pointer
await pointer.move_to(500, 200, smooth_soft=60, total_time=0.5)
await pointer.move_to(20, 50, smooth_soft=60, total_time=0.5)
await pointer.move_to(8, 45, smooth_soft=60, total_time=0.5)
await pointer.move_to(500, 200, smooth_soft=60, total_time=0.5)
await pointer.move_to(166, 206, smooth_soft=60, total_time=0.5)
await pointer.move_to(200, 205, smooth_soft=60, total_time=0.5)
iframes = await driver.find_elements(By.TAG_NAME, "iframe")
await asyncio.sleep(0.5)
targets = await driver.get_targets_for_iframes(iframes)
target = None
for target in targets:
# filter out correct iframe target
text = None
try:
elem = await target.find_element(By.CSS_SELECTOR, "body > div.overlay")
text = await elem.text
except NoSuchElementException:
pass
finally:
if text: # 'Only a test.' text
break
if not target:
raise Exception("correct target for iframe not found")
src = await driver.page_source
checkbox = await target.find_element(By.CSS_SELECTOR, "#challenge-stage > div > label > input[type=checkbox]", timeout=20)
await checkbox.click(move_to=True)
await asyncio.sleep(5)
print("saving screenshot")
await driver.save_screenshot("turnstile_captcha.png")
asyncio.run(main())
I can't reproduce this issue :(
related to https://github.com/ChromeDevTools/devtools-protocol/issues/72, not that easy to resolve.
@kaliiiiiiiiii Sorry for the wait, your demo returns this screenshot:
And "correct target for iframe not found" isn't printed, so it works.
For some weird reason, this site that I'm trying to automate doesn't work with your code.. Have you figured out a solution yet?
@Fragaile Yep, the solution is already available in the dev
-branch and will be released probably within about 24hrs. (see Readme.md in dev
-branch for updaten usage and installation)
Basically, it occurs because some iframes are now targets (some cross-origin ones) and others are within the same target.
@kaliiiiiiiiii
iframe_document = await iframes[0].content_document
.content_document
doesnt seem to be an actual thing.. I tried reinstalling your package.
AttributeError: 'WebElement' object has no attribute 'content_document'
NEVERMIND!! I installed the regular version, not dev, sorry.
@Fragaile
This should be resolved with selenium-driverless==1.6
Please close this issue if it's fixed now:)
I tried everything, read every closed issue and all your documentation, iframes will just refuse to be found.
Modified code (CLASS_NAME is js-frame, because that's what my site uses)
Element is found but driver.get_target_for_iframe() doesnt work, it throws this error:
If I do the same with selenium, it works perfectly.