Unable to switch to frame in loop in selenium

Viewed 69

`I am trying to switch to particular frame using selenium python in loop. It gets executed the first time but after that gives timeout exception error. Here is the code:

    Navigate.py:
        def navigate_to_frame(): 
        
      driver.switch_to.default_content() 
//Navigation to the frame using execute script

action.py
def perform():  
    driver.switch_to.default_content()
   
 driver.switch_to.frame(frame)   
//Perform required actions

Start.py


for i in range(0,5):

    navigate_to_frame()

    perform()

The above code works for first time but in the second iteration it throws an exception

1 Answers

I found the solution somewhere else. Came back to answer it.

You are still in the first frame from your first iteration when you try to select from the second iteration.

You need to leave the frame it at the end of the first loop to reset where you are looking at. For example with. a "select frame relative=top".

Related