Cannot find frame errors

30 views
Skip to first unread message

Edward Markiewicz

unread,
Jun 25, 2024, 2:13:10 PM (7 days ago) Jun 25
to Selenium Users
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


Adrian

unread,
Jun 25, 2024, 5:06:12 PM (7 days ago) Jun 25
to Selenium Users
Hi,
We will need more information to be able to provide guidance on this.

Which part is it actually failing on?
Is the variable myFrame null, so it does not work for the line: driver.switch_to.frame(myFrame)
Or is the variable eventFilterForm null?


Just looking at the code, I can see a bit to fix up.
The xpath you are using (/html/body/div[8]/div[3]/div[1]/div[2]/div[1]/a) will make your test brittle and easily broken.  Without seeing the DOM at this stage, I cannot recommend what the best xpath should be.

The time.sleep(3) should be replaced with something like:
wait = WebDriverWait(driver, 10)
myFrame = wait.until(EC.visibilty_of_element_located(By.ID, 'popover_form'))

This will wait for up to 10 seconds for the popover form to be visible - which could happen in 1 second and will save you waiting an extra 2 seconds.

Remove the line below as it doesn't do anything

myFrame = driver.find_elements(By.XPATH, '/html/body/div[1]/div/form')

Then continue with the rest of your code up to:
driver.switch_to.frame(driver.find_element_by_tag_name("frame"))

I'm not sure the line of code above is correct as it tries to find the tag "frame".  From the part of the dom that you have posted, there is no tag called frame.

NOTE: I do not use python, so some changes to my code examples maybe required.


Cheers,
Adrian. 
Reply all
Reply to author
Forward
0 new messages