如何在selenium webdriver的chrome上下文中访问firefox iframe选择菜单?

如何在selenium webdriver的chrome上下文中访问firefox iframe选择菜单?,selenium,selenium-webdriver,iframe,Selenium,Selenium Webdriver,Iframe,我在Firefox中使用Python,并试图 导航到嵌入框架的网页 在Firefox中打开devtools菜单Ctrl+Shift+K 从devtools公开的iframe中选择另一个iframe。 问题: 如何做到这一点 我所尝试的: 我当前的脚本是 #!/usr/bin/env python from selenium.webdriver import Firefox, DesiredCapabilities, FirefoxProfile from selenium.webdriver.

我在Firefox中使用Python,并试图

导航到嵌入框架的网页 在Firefox中打开devtools菜单Ctrl+Shift+K 从devtools公开的iframe中选择另一个iframe。 问题: 如何做到这一点

我所尝试的: 我当前的脚本是

#!/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()

我的旧答案不再有效,因为在那个时候,相同的元素是一个iframe,我可以简单地切换到它

webdriver.switch_to.frame(<iframe>)

我也尝试过用ifr单击它。单击无效:我在Firefox窗口中没有看到任何事件,脚本打开时也没有错误。

webdriver.switch\u to.frame这已更改为driver.switch\u to.frame,完全没有区别:selenium.common.exceptions.NoSuchFrameException:消息:无法找到framefor element:[对象XULFrameElement。关键是它不是一个框架,所以不会切换到它。该元素位于浏览器标记中,我想知道如何处理它。请参阅我的评论。基本上,当您只是自动化网站时,您不应该将上下文切换到chrome。我建议关闭/复制此主题。
webdriver.switch_to.frame(<iframe>)