I'm attempting to use Selenium to run a function within a different frame. Within the Chrome console I can call the function when residing within the context:
However, I cannot call the function from the top level:
The code that I have right now is as follows:
from seleniumwire import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("MY_WEBSITE")
frame_id = "main-iframe"
WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.ID, """main-iframe""")))
driver.switch_to.frame(driver.find_element_by_id(frame_id))
driver.execute_script("onCaptchaFinished();")
But this returns the following error:
JavascriptException: Message: ReferenceError: onCaptchaFinished is not defined
Any help would be massively appreciated. Note that this question is not similar to earlier questions, as I am specifically attempting to run a Javascript function from within an iframe, something that no questions have gone over.