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
inFirefox
) - 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).