[−][src]Struct thirtyfour_sync::SwitchTo
Struct for switching between frames/windows/alerts.
Implementations
impl<'a> SwitchTo<'a>
[src]
pub fn new(session: &'a WebDriverSession) -> Self
[src]
Create a new SwitchTo struct. This is typically created internally
via a call to WebDriver::switch_to()
.
pub 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()?; assert_eq!(elem.tag_name()?, "body"); // Now let's manually focus an element and try active_element() again. driver.execute_script(r#"document.getElementsByName("input1")[0].focus();"#)?; let elem = driver.switch_to().active_element()?; elem.send_keys("selenium")?;
pub fn alert(self) -> Alert<'a>
[src]
Return Alert struct for processing the active alert on the page.
See Alert documentation for examples.
pub fn default_content(self) -> WebDriverResult<()>
[src]
Switch to the default frame.
Example:
driver.switch_to().frame_number(0)?; // We are now inside the iframe. driver.find_element(By::Id("button1"))?; driver.switch_to().default_content()?; // We are now back in the original window.
pub 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)?; // We can now search for elements within the iframe. let elem = driver.find_element(By::Id("button1"))?; elem.click()?;
pub fn frame_element(
self,
frame_element: &WebElement<'_>
) -> WebDriverResult<()>
[src]
self,
frame_element: &WebElement<'_>
) -> WebDriverResult<()>
Switch to the specified iframe element.
Example:
let elem_iframe = driver.find_element(By::Id("iframeid1"))?; driver.switch_to().frame_element(&elem_iframe)?; // We can now search for elements within the iframe. let elem = driver.find_element(By::Id("button1"))?; elem.click()?;
pub fn parent_frame(self) -> WebDriverResult<()>
[src]
Switch to the parent frame.
Example:
let elem_iframe = driver.find_element(By::Id("iframeid1"))?; driver.switch_to().frame_element(&elem_iframe)?; // We can now search for elements within the iframe. let elem = driver.find_element(By::Id("button1"))?; elem.click()?; // Now switch back to the parent frame. driver.switch_to().parent_frame()?; // We are now back in the parent document.
pub 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");"#)?; // Get window handles and switch to the new tab. let handles = driver.window_handles()?; driver.switch_to().window(&handles[1])?; // We are now controlling the new tab. driver.get("http://webappdemo")?;
pub 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")?
.
Example:
// Set main window name so we can switch back easily. driver.set_window_name("mywindow")?; // Open a new tab. driver.execute_script(r#"window.open("about:blank", target="_blank");"#)?; // Get window handles and switch to the new tab. let handles = driver.window_handles()?; driver.switch_to().window(&handles[1])?; // We are now controlling the new tab. assert_eq!(driver.title()?, ""); driver.switch_to().window_name("mywindow")?; // We are now back in the original tab. assert_eq!(driver.title()?, "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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,