selenium.webdriver.remote.switch_to

Classes

SwitchTo(driver)
class selenium.webdriver.remote.switch_to.SwitchTo(driver)[source]
active_element

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

Usage:
element = driver.switch_to.active_element
alert

Switches focus to an alert on the page.

Usage:
alert = driver.switch_to.alert
default_content() → None[source]

Switch focus to the default frame.

Usage:
driver.switch_to.default_content()
frame(frame_reference: Union[str, int, selenium.webdriver.remote.webelement.WebElement]) → None[source]

Switches focus to the specified frame, by index, name, or webelement.

Args:
  • frame_reference: The name of the window to switch to, an integer representing the index,
    or a webelement that is an (i)frame to switch to.
Usage:
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: Optional[str] = None) → 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.

Usage:
driver.switch_to.new_window('tab')
parent_frame() → None[source]

Switches focus to the parent context. If the current context is the top level browsing context, the context remains unchanged.

Usage:
driver.switch_to.parent_frame()
window(window_name: str) → None[source]

Switches focus to the specified window.

Args:
  • window_name: The name or window handle of the window to switch to.
Usage:
driver.switch_to.window('main')