[][src]Struct thirtyfour::SwitchTo

pub struct SwitchTo<'a> { /* fields omitted */ }

Struct for switching between frames/windows/alerts.

Methods

impl<'a> SwitchTo<'a>[src]

pub fn new(driver: WebDriverSession<'a>) -> Self[src]

Create a new SwitchTo struct. This is typically created internally via a call to WebDriver::switch_to().

pub async fn active_element(self) -> WebDriverResult<WebElement<'a>>[src]

Return the element with focus, or the <body> element if nothing has focus.

Example:

// If no element has focus, active_element() will return the body tag.
let elem = driver.switch_to().active_element().await?;
assert_eq!(elem.tag_name().await?, "body");
// Now let's manually focus an element and try active_element() again.
driver.execute_script(r#"document.getElementsByName("input1")[0].focus();"#).await?;
let elem = driver.switch_to().active_element().await?;
elem.send_keys("selenium").await?;

pub fn alert(self) -> Alert<'a>[src]

Return Alert struct for processing the active alert on the page.

See Alert documentation for examples.

pub async fn default_content(self) -> WebDriverResult<()>[src]

Switch to the default frame.

Example:

driver.switch_to().frame_number(0).await?;
// We are now inside the iframe.
driver.find_element(By::Id("button1")).await?;
driver.switch_to().default_content().await?;
// We are now back in the original window.

pub async fn frame_number(self, frame_number: u16) -> WebDriverResult<()>[src]

Switch to an iframe by index. The first iframe on the page has index 0.

Example:

driver.switch_to().frame_number(0).await?;
// We can now search for elements within the iframe.
let elem = driver.find_element(By::Id("button1")).await?;
elem.click().await?;

pub async fn frame_element<'_>(
    self,
    frame_element: &'_ WebElement<'a>
) -> WebDriverResult<()>
[src]

Switch to the specified iframe element.

Example:

let elem_iframe = driver.find_element(By::Id("iframeid1")).await?;
driver.switch_to().frame_element(&elem_iframe).await?;
// We can now search for elements within the iframe.
let elem = driver.find_element(By::Id("button1")).await?;
elem.click().await?;

pub async fn parent_frame(self) -> WebDriverResult<()>[src]

Switch to the parent frame.

Example:

let elem_iframe = driver.find_element(By::Id("iframeid1")).await?;
driver.switch_to().frame_element(&elem_iframe).await?;
// We can now search for elements within the iframe.
let elem = driver.find_element(By::Id("button1")).await?;
elem.click().await?;
// Now switch back to the parent frame.
driver.switch_to().parent_frame().await?;
// We are now back in the parent document.

pub async fn window<'_>(self, handle: &'_ WindowHandle) -> WebDriverResult<()>[src]

Switch to the specified window.

Example:

// Open a new tab.
driver.execute_script(r#"window.open("about:blank", target="_blank");"#).await?;
// Get window handles and switch to the new tab.
let handles = driver.window_handles().await?;
driver.switch_to().window(&handles[1]).await?;
// We are now controlling the new tab.
driver.get("http://webappdemo").await?;

pub async fn window_name<'_>(self, name: &'_ str) -> WebDriverResult<()>[src]

Switch to the window with the specified name. This uses the window.name property. You can set a window name via WebDriver::set_window_name("someName").await?.

Example:

// Set main window name so we can switch back easily.
driver.set_window_name("mywindow").await?;
// Open a new tab.
driver.execute_script(r#"window.open("about:blank", target="_blank");"#).await?;
// Get window handles and switch to the new tab.
let handles = driver.window_handles().await?;
driver.switch_to().window(&handles[1]).await?;
// We are now controlling the new tab.
assert_eq!(driver.title().await?, "");
driver.switch_to().window_name("mywindow").await?;
// We are now back in the original tab.
assert_eq!(driver.title().await?, "Demo Web App");

Auto Trait Implementations

impl<'a> !RefUnwindSafe for SwitchTo<'a>

impl<'a> Send for SwitchTo<'a>

impl<'a> Sync for SwitchTo<'a>

impl<'a> Unpin for SwitchTo<'a>

impl<'a> !UnwindSafe for SwitchTo<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.