How to switch between frames using selenium library with Python?

I trying to switch frame "top" to "body". I tried different ways but I couldn't do it. There is too much source but any of them not working. What is the problem with it? HTML structure is in the link. Page is "jsp".

# 1 
driver.switch_to_frame("body")

# 2
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"/html/frameset/frame[3]")))

Maybe the problem is visibility?

Upvotes: 0

Views: 1461

Answers (2)

Kuldeep Kamune
Kuldeep Kamune

Reputation: 169

As mentioned in question, your trying to switch directly from one frame to another frame, which are on same level in DOM like:

<iframe name="top"></iframe>
<iframe name="body"></iframe>

You need to switch to defaultContent before switching to another frame using:

driver.switch_to.default_content()

Then try to switch to frame body

driver.switch_to_frame("body")

We can not directly switch from one frame to another unless targeted frame is located within current frame.

Ex:

<iframe name="top">
    <iframe name="body"></iframe>
</iframe>

Then, we can use:

driver.switch_to_frame("top")
driver.switch_to_frame("body")

Upvotes: 0

Shrini
Shrini

Reputation: 193

Switch to default content from frame "top" and then switch to "body".

driver.switch_to_default_content()

Upvotes: 1

Related Questions