frame_by_element

The command to switch the driver's context to the given element.

Syntax

py.switch_to.frame_by_element(element: Element, timeout: int = 0) -> Pylenium

Usage

correct usage
iframe = py.get("iframe")
py.switch_to.frame_by_element(iframe)

---or--- # chain a Pylenium command

iframe = py.get("iframe")
py.switch_to.frame_by_element(iframe).contains("Add New").click()

Arguments

  • element (Element) - The Element to switch to

  • timeout=0 (int) - The number of seconds to wait for the frame to be switched to

Yields

  • Pylenium - The current instance of Pylenium so you can chain commands

Examples

<div>
    <frame id='foo'>
        <a href='/different-page' id='bar'>Link in iframe</a>
    </frame>
</div>

If we wanted to click the link above, we would need to:

  1. Switch the driver's context to the iframe

  2. Then perform the click

This is a piece of cake with Pylenium:

iframe = py.get("#foo")
py.switch_to.frame_by_element(iframe).get("#bar").click()

Last updated