I'm trying to run a script using Selenium/Python but keep getting "no such frame" errors. my environment is:
- Running on an HP laptop with Windows 11 installed.
- I'm using Anaconda/Spyder as my IDE.
- I am using Python 3.11.9.
- I am using Selenium 4.21.0.
Here is a code snippet of what I'm trying to run:
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By
from selenium.webdriver import Keys
from webdriver_manager.chrome import ChromeDriverManager
# Use a local version of chromedriver
cService = webdriver.ChromeService(executable_path='./chromedriver.exe')
driver = webdriver.Chrome(service = cService)
#Open a browser
driver.get(<URL address>)
# Select the icon to bring up the form pop-up
driver.find_element(By.XPATH, '/html/body/div[8]/div[3]/div[1]/div[2]/div[1]/a').click()
time.sleep(3)
"""
Everything works up to here! I get the form pop-up.
"""
Here are some of the techniques I've tried but nothing worked.
myFrame = driver.find_elements(By.XPATH, '/html/body/div[1]/div/form')
myFrame = driver.find_elements(By.CSS_SELECTOR, "#popover_form > frame")
driver.switch_to.frame(myFrame)
eventFilterForm = driver.find_element(By.ID, "EventFilterEventIndexForm")
driver.switch_to.frame(eventFilterForm)
driver.switch_to.window(driver.find_element(By.CSS_SELECTOR, '#EventFilterEventIndexForm'))
driver.switch_to.frame(driver.find_element_by_tag_name("frame"))
Here is the information I found using the inspect function:
<div id="popover_form" class="ajax_popover_form" style="display: block;">
<div class="events">
<form action="/events/filterEventIndex?_=1719337225299" id="EventFilterEventIndexForm" method="post" accept-charset="utf-8"><div style="display:none;"><input type="hidden" name="_method" value="POST"><input type="hidden" name="data[_Token][key]" value="7d6603b094e3ef385e395f404eaf1c8b" id="Token1200624128" autocomplete="off"></div>
Any help on this will be appreciated.
!Ed