[][src]Struct selenium_webdriver::Browser

pub struct Browser { /* fields omitted */ }

Main crate struct

Contains methods for manipulating the browser session, internally making requests to the selenium server. All methods that create local sessions imply that the selenium server is running on port 4444

Implementations

impl Browser[src]

pub fn start_session(browser: BrowserName, args: Vec<&str>) -> Browser[src]

Method to construct the Browser instance with basic session. Supports args for Chrome, while for Firefox and Safari they will be ignored. To customize the Chrome and Firefox sessions pls use the corresponding method start_..._session_with_options().

Examples

let mut browser = Browser::start_session(BrowserName::Chrome,vec!["--headless"]);
browser.close_browser();

pub fn start_session_with_capabilities(
    capabilities: Capabilities
) -> Result<Browser, String>
[src]

Allows to create a customized session with various capabilities. For details please check the docs for the Capabilities struct and its methods.

Examples


let mut ch_op = ChromeOptions::new();
ch_op.add_args(vec!["--headless","--window-size=500,1000"]);
ch_op.add_mobile_emulation(MobileDevice::standard_device("Nexus 6"));

let mut c = Capabilities::new(BrowserName::Chrome, "windows");
c.set_chrome_options(ch_op);

let mut br = Browser::start_session_with_capabilities(c).unwrap();
br.open("https://vk.com").unwrap();
br.take_screenshot("vk.png").unwrap();
br.close_browser().unwrap();
let res = std::fs::read("vk.png");
assert!(res.is_ok());
std::fs::remove_file("vk.png").unwrap();

pub fn start_remote_session_with_capabilities(
    capabilities: Capabilities,
    ip: &str,
    port: &str
) -> Result<Browser, String>
[src]

Does the same thing as the start_session_with_capabilities(),but for the remote session.

pub fn start_remote_session(
    browser: BrowserName,
    platform: &str,
    ip: &str,
    port: &str
) -> Result<Browser, String>
[src]

Method to construct the Browser instance with basic remote session. Also intended to add chrome/firefox/safari options to the remote sessions.

pub fn start_chrome_session_with_options(
    options: ChromeOptions
) -> Result<Browser, String>
[src]

Method to start the session customized with ChromeOptions

Examples

let mut ch = ChromeOptions::new();
let mob = MobileDevice::standard_device("Nexus 6");
ch.add_args(vec!["--headless","--window-size=400,600"]);
ch.add_mobile_emulation(mob);
let mut br = Browser::start_chrome_session_with_options(ch).unwrap();
let res = br.open("https://vk.com");
let res2 = br.close_browser();
assert!(res.is_ok()&&res2.is_ok());

pub fn start_firefox_session_with_options(
    options: FirefoxOptions
) -> Result<Browser, String>
[src]

Method to start the Firefox session adjusted with FirefoxOptions Works similar to the ChromeOptions. For more info please check the FirefoxOptions docs.

pub fn start_safari_session_with_options(
    options: SafariOptions
) -> Result<Browser, String>
[src]

Method to start the Safari with settings. Works similar to the ChromeOptions and FFOptions. For more info please check the SafariOptions docs.

pub fn open(&self, uri: &str) -> Result<(), String>[src]

Open a webpage or a local file

Get the url of the current page.

pub fn close_browser(&mut self) -> Result<(), String>[src]

Deletes current session. As the Browser struct needs dropping, it is better to call drop() after this method in long-multibrowser scenarios.

pub fn get_timeouts(&self) -> Result<Timeouts, String>[src]

Returns the session timouts data

pub fn set_timeouts(&self, timeouts: &Timeouts) -> Result<(), &str>[src]

Change the session timouts data

pub fn back(&self) -> Result<(), String>[src]

Return to the previous page

pub fn forward(&self) -> Result<(), String>[src]

pub fn refresh(&self) -> Result<(), &str>[src]

pub fn get_title(&self) -> Result<String, String>[src]

Returns the title of the current tab

pub fn get_window_handle(&self) -> Result<String, String>[src]

Returns the handle of the current window, which later may be used to switch to this window.

pub fn get_window_handles(&self) -> Result<Vec<String>, String>[src]

Returns the handles of all open windows and tabs

pub fn switch_to_window(&self, window_id: String) -> Result<(), String>[src]

Switches to the window with the passed id

pub fn new_window(
    &self,
    window_type: NewWindowType
) -> Result<(String, String), String>
[src]

Opens a new window or a new tab depending on the window_type

pub fn close_window(&self) -> Result<Vec<String>, String>[src]

Closes the window and returns the vector of the remaining window handles

pub fn switch_to_frame_by_id(&self, id: u64) -> Result<(), String>[src]

Switches to the frame with a given id. For instance, if there are 4 frames and you wish to switch to the second one, you should call this method like this - switch_to_frame_by_id(1).

pub fn switch_to_frame_by_element(&self, element: Element) -> Result<(), String>[src]

pub fn switch_to_parent_frame(&self) -> Result<(), String>[src]

pub fn get_active_element(&self) -> Result<Element, String>[src]

pub fn find_element(
    &self,
    loc_strategy: LocatorStrategy
) -> Result<Element, String>
[src]

If the locator matches several elements, it returns the first one

Examples


let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless"]);
br.open("https://vk.com").unwrap();
let el = br.find_element(LocatorStrategy::CSS("#ts_input")).unwrap();
let res = el.click(); 
br.close_browser().unwrap();
assert!(res.is_ok()); 

pub fn find_elements(
    &self,
    loc_strategy: LocatorStrategy
) -> Result<Vec<Element>, String>
[src]

pub fn get_window_rect(&self) -> Result<WindowRect, String>[src]

Returns the WindowRect instance which contains the information about the position and size of the current window

pub fn set_sindow_rect(
    &self,
    window_rect: &WindowRect
) -> Result<WindowRect, String>
[src]

Allow to resize the window and change it's position

pub fn maximize_window(&self) -> Result<WindowRect, String>[src]

pub fn minimize_window(&self) -> Result<WindowRect, String>[src]

pub fn fullscreen(&self) -> Result<WindowRect, String>[src]

pub fn source(&self) -> Result<String, String>[src]

Returns the page source code

pub fn get_all_cookies(&self) -> Result<Vec<Cookie>, String>[src]

Return the vector with all the cookies that the browser is holding at the moment

Returns the information on a particular cookie

pub fn delete_all_cookies(&self) -> Result<(), String>[src]

pub fn take_screenshot(&self, path: &str) -> Result<(), String>[src]

The path should be absolute with the extension

Examples

let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=7680,4320"]);
br.open("https://vk.com").unwrap();
br.take_screenshot("screen.png").unwrap();
br.close_browser().unwrap();

pub fn take_element_screenshot(
    &self,
    elem: &Element,
    path: &str
) -> Result<(), String>
[src]

pub fn execute_sync(
    &self,
    script: &str,
    args: &Vec<&str>
) -> Result<String, String>
[src]

Executes the sync fun in the browser. In case the argument is a string, it should be a raw string or should incluse escapes with double quotes For example, if the args list you want to pass is [5,"Jack", 15], the vector should be ["5",r#"Jack"#,"15"]

pub fn execute_async(
    &self,
    script: &str,
    args: &Vec<&str>
) -> Result<String, String>
[src]

Executes the async fun in the browser. The args should be passed similarly to the execute_sync fn.

pub fn print(
    &self,
    print_settings: &PrintSettings,
    path: &str
) -> Result<(), String>
[src]

Prints out the page. If you want to print it to pdf, use headless mode. The structs PrintSettings,Page and Margin allow you to customize the print.

impl Browser[src]

pub fn dismiss_alert(&self) -> Result<(), String>[src]

pub fn allow_alert(&self) -> Result<(), String>[src]

pub fn get_alert_text(&self) -> Result<String, String>[src]

pub fn send_alert_text(&self, text: &str) -> Result<(), String>[src]

pub fn perform_actions(&self, actions: Actions) -> Result<(), String>[src]

Pls see the Actions struct page to learn how to properly construct the Actions instance.

Examples

let mut actions = Actions::new();
let mut actions_keys = ActionsKeys::new();
actions_keys.press_special_key(SpecialKey::ShiftLeft);
actions_keys.press_key("a");
actions.add_key_actions(actions_keys);
let mut br = Browser::start_session(BrowserName::Chrome,  vec!["--headless","--window-size=1000,500"]);
br.open("https:vk.com/").unwrap();
br.find_element(LocatorStrategy::CSS("#ts_input")).unwrap().click().unwrap();
br.perform_actions(actions);
br.close_browser().unwrap();

pub fn release_actions(&self) -> Result<(), String>[src]

Releases all the actions present in the current session's internal state. While the key actions are performed just after calling the perform_actions method, for instance, mouse actions are performed only after calling this method.

Trait Implementations

impl Debug for Browser[src]

Auto Trait Implementations

impl RefUnwindSafe for Browser

impl Send for Browser

impl Sync for Browser

impl Unpin for Browser

impl UnwindSafe for Browser

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.