Search code examples
seleniumselenium-webdriveriframewebdriverframe

How to validate the focus of the WebDriver while switching frames


I go to the frame on the site using the code

driver.SwithToFrame(0)

How can I find out now in focus the main site or frame?


Solution

  • To validate if the focus is on the Top Browsing Context or within the , you can switch to the active_element and then print the outerHTML and you can use the following solution:

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