0

I am using Python's Selenium Webdriver with Firefox, and trying to

  • navigate to a webpage that embeds a frame
  • open the devtools menu (Ctrl+Shift+K in Firefox)
  • select this other iframe from the iframe context picker exposed by devtools.

Question: How to achieve this?

What I've tried: My current script reads

#!/usr/bin/env python

from selenium.webdriver import Firefox, DesiredCapabilities, FirefoxProfile
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options

import time
import traceback
import os

options = Options()
options.add_argument("-devtools")
webdriver = Firefox(options=options)

webdriver.get(<url that will embed the iframe>)

try:
    <do a bunch of stuff that will trigger the appearance of the iframe>
except:
    pass

try:
    time.sleep(3)
    with webdriver.context(webdriver.CONTEXT_CHROME):
        ifr =
webdriver.find_element_by_class_name("devtools-toolbox-bottom-iframe")
        
except Exception as error:
    traceback.print_exc()

This doesn't complain, because it does find an element with class devtools-toolbox-bottom-iframe. My problem is that I do not know what to do with it afterwards to access the iframe-selection menu underneath. That element has a tag of browser, i.e. looks like this:

<browser type="content" flex="1" class="devtools-toolbox-bottom-iframe" height="250" aria-label="Developer Tools" src="about:devtools-toolbox" session_id="910"/>

This old answer of mine no longer works, because back then this same element was an iframe and I could simply switch to it with

webdriver.switch_to.frame(<iframe>)

I have also tried clicking it (with ifr.click()) to no effect: I see nothing happening in the Firefox window that the script opens (no errors either though).

grobber
  • 1,083
  • 1
  • 9
  • 20
  • `webdriver.switch_to.frame( – Dev May 05 '21 at 09:41
  • That makes absolutely no difference: `selenium.common.exceptions.NoSuchFrameException: Message: Unable to locate frame for element: [object XULFrameElement`. The point is that's not a frame, so it won't "switch" to it. The element is in a `browser` tag, and I am asking what to do with that.. – grobber May 05 '21 at 12:11
  • See my comment over on https://stackoverflow.com/questions/63680269/is-it-possible-to-emulate-the-firefox-console-cd-function-and-or-javascript-cont/67434213#67434213. Basically you should never switch context to `chrome` when you are just automating web sites. I would suggest to close / duplicate this topic. – Henrik May 07 '21 at 11:37

0 Answers0