如何在切换框架时验证 WebDriver 的焦点

How to validate the focus of the WebDriver while switching frames

我使用代码进入网站上的框架

driver.SwithToFrame(0)

我怎样才能找到现在处于焦点中的主站点或框架?

要验证焦点是在热门浏览上下文上还是在内,您可以切换到active_element 然后打印 outerHTML 可以使用以下解决方案:

driver.switch_to.frame(0)
element = driver.switch_to.active_element
print(element.get_attribute("outerHTML"))