4

I'm working on a page with nested frames, and am unable to access a child frame. Brief outline of HTML source:

<html>
    <head></head>
    <frameset id="0">
        <frame name="name">
        <frameset cols="10%,20%" id="01">
            <frame name="mid1">
            <frame name="mid2" scrolling="auto" src="chkclineversion.asp" marginwidth="0" marginheight="0"> 
        </frameset>
        <frame name="bot">
    </frameset>
</html>

I need to access the frame named "mid2". This frame is nested within a frameset which is in turn nested within the main frameset.

I've tried the following codes but they do work

driver.switch_to_frame("mid2") #direct reference to nested frame name

driver.switch_to_frame(1)
driver.switch_to_frame("mid2") #switch to subframe by index and then attempt to reference "mid2". This gives me a no such frame exception1

Am I missing something obvious?

I've checked this link but it does not clarify my question.

Thanks

2 Answers 2

4

Try this:

driver.switch_to_frame("name")
driver.switch_to_frame("mid2")

The issue you're running into is that javascript can only work with the current frame it sees. mid2 is in a child frame it cannot see if you're at the top of the document.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. The issue though is that the frame 'name' is not the parent frame of 'mid2'. 'mid2' is part of the sub-frameset with id '01'.
2

The <frame> tag with name as mid2 seems to be nested within 2 additional layers of <frame>.

to access the <frame> with name attribute as mid2 you have to:

  • Ignore (safely) the presence of parent / child <frameset> tags.
  • Induce WebDriverWait for the first layer of <frame> to be available and switch to it.
  • Induce WebDriverWait for the second layer of <frame> to be available and switch to it.
  • Induce WebDriverWait for the desired <frame> to be available and switch to it.
  • You can use the following solution:

    • Code Block:

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"name")))
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"frame[name='mid1']")))
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//frame[@name='mid2' and starts-with(@src, 'chkclineversion')]")))
      
    • Note : You have to add the following imports :

      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.common.by import By
      from selenium.webdriver.support import expected_conditions as EC
      

You can find a relevant discussion in How to locate and click on an element which is nested within multiple frame and frameset through Selenium using Webdriver and C#


Outro

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.