selenium.webdriver.remote.switch_to#

Classes

SwitchTo(driver)

class SwitchTo(driver)[source]#

Bases: object

property active_element: WebElement#

Returns the element with focus, or BODY if nothing has focus.

Example

element = driver.switch_to.active_element

property alert: Alert#

Switches focus to an alert on the page.

Example

alert = driver.switch_to.alert

default_content()[source]#

Switch focus to the default frame.

Example

driver.switch_to.default_content()

Return type:

None

frame(frame_reference)[source]#

Switch focus to the specified frame by index, name, or element.

Parameters:

frame_reference (str | int | WebElement) – The name of the frame to switch to, an integer representing the index, or a WebElement that is an (i)frame to switch to.

Return type:

None

Example

driver.switch_to.frame(“frame_name”) driver.switch_to.frame(1) driver.switch_to.frame(driver.find_elements(By.TAG_NAME, “iframe”)[0])

new_window(type_hint=None)[source]#

Switches to a new top-level browsing context.

The type hint can be one of “tab” or “window”. If not specified the browser will automatically select it.

Example

driver.switch_to.new_window(“tab”)

Parameters:

type_hint (str | None)

Return type:

None

parent_frame()[source]#

Switch focus to the parent browsing context.

If the current context is already the top level browsing context, it remains unchanged.

Example

driver.switch_to.parent_frame()

Return type:

None

window(window_name)[source]#

Switches focus to the specified window.

Parameters:

window_name (str) – The name or window handle of the window to switch to.

Return type:

None

Example

driver.switch_to.window(“main”)