0

I'm trying to switch to an iframe so then I can fill a box. The iframe has a dynamic id so I cannot use that, it has a class and a title which I have converted into an XPath. However, I do not seem to get an error when switching to iframe but when it tries to fill it gives an error. Here is my code.

iframe1 = page.query_selector('xpath=//iframe[@title="payment"]').content_frame()
time.sleep(5)
iframe1.fill('//*[@id="cardCvc-input"]', '123')

Error

Traceback (most recent call last):
  File "C:\Python39\lib\threading.py", line 950, in _bootstrap_inner
    self.run()
  File "C:\Python39\lib\threading.py", line 888, in run
    self._target(*self._args, **self._kwargs)
  File "c:\Users\Owner\Desktop\Cheema AIO\snkrsplaywright.py", line 194, in main
    frame_element_handle = page.query_selector('//iframe[@title="payment"]')
  File "C:\Python39\lib\site-packages\playwright\sync_api\_generated.py", line 4920, in query_selector
    self._sync(
  File "C:\Python39\lib\site-packages\playwright\_impl\_sync_base.py", line 103, in _sync
    return task.result()
  File "C:\Python39\lib\site-packages\playwright\_impl\_page.py", line 346, in query_selector
    return await self._main_frame.query_selector(selector)
  File "C:\Python39\lib\site-packages\playwright\_impl\_frame.py", line 228, in query_selector
    await self._channel.send("querySelector", dict(selector=selector))
  File "C:\Python39\lib\site-packages\playwright\_impl\_connection.py", line 36, in send
    return await self.inner_send(method, params, False)
  File "C:\Python39\lib\site-packages\playwright\_impl\_connection.py", line 47, in inner_send
    result = await callback.future
playwright._impl._api_types.Error: Execution context was destroyed, most likely because of a navigation.
pavelsaman
  • 7,399
  • 1
  • 14
  • 32
CheemaOTB
  • 39
  • 1
  • 3

1 Answers1

0

Version 1.22

iframe = page.frame_locator("YOUR_SELECTOR_HERE")

https://playwright.dev/python/docs/api/class-framelocator

Min ho Kim
  • 59
  • 2
  • 5