Struct ChromeDriver

Source
pub struct ChromeDriver {
    pub version: String,
    pub browser_version: String,
    /* private fields */
}

Fields§

§version: String

Chrome driver version

§browser_version: String

Chrome browser version

Implementations§

Source§

impl ChromeDriver

Source

pub fn new() -> Self

Create driver

Examples found in repository?
examples/default_args.rs (line 5)
4async fn main() {
5    let mut driver = ChromeDriver::new();
6    driver.init().await.unwrap();
7
8    println!("driver version {}", driver.version);
9    println!("browser version {}", driver.browser_version);
10
11    if driver.need_download() {
12        driver.try_download().await.unwrap();
13    }
14}
More examples
Hide additional examples
examples/custom_args.rs (line 5)
4async fn main() {
5    let mut driver = ChromeDriver::new();
6    driver
7        .set_driver_path("/usr/local/bin/chromedriver")
8        .set_browser_path("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
9        .set_connect_timeout(2000)
10        .set_timeout(5000)
11        .init()
12        .await
13        .unwrap();
14
15    println!("driver version {}", driver.version);
16    println!("browser version {}", driver.browser_version);
17
18    if !driver.need_download() {
19        println!("no need to update driver");
20        return;
21    }
22
23    println!("updating driver ...");
24
25    match driver.try_download().await {
26        Ok(_) => println!("Download driver successful"),
27        Err(err) => eprintln!("Download driver failed, {}", err),
28    }
29}
Source

pub fn set_driver_path(&mut self, path: &str) -> &mut Self

Update chromedriver path. Default:

  • mac: /usr/local/bin/chromedriver
  • linux: /usr/bin/chromedriver
  • windows: ``
Examples found in repository?
examples/custom_args.rs (line 7)
4async fn main() {
5    let mut driver = ChromeDriver::new();
6    driver
7        .set_driver_path("/usr/local/bin/chromedriver")
8        .set_browser_path("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
9        .set_connect_timeout(2000)
10        .set_timeout(5000)
11        .init()
12        .await
13        .unwrap();
14
15    println!("driver version {}", driver.version);
16    println!("browser version {}", driver.browser_version);
17
18    if !driver.need_download() {
19        println!("no need to update driver");
20        return;
21    }
22
23    println!("updating driver ...");
24
25    match driver.try_download().await {
26        Ok(_) => println!("Download driver successful"),
27        Err(err) => eprintln!("Download driver failed, {}", err),
28    }
29}
Source

pub fn set_browser_path(&mut self, path: &str) -> &mut Self

Update chrome browser path. Default:

  • mac: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
  • linux: /usr/bin/google-chrome
  • windows: ``
Examples found in repository?
examples/custom_args.rs (line 8)
4async fn main() {
5    let mut driver = ChromeDriver::new();
6    driver
7        .set_driver_path("/usr/local/bin/chromedriver")
8        .set_browser_path("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
9        .set_connect_timeout(2000)
10        .set_timeout(5000)
11        .init()
12        .await
13        .unwrap();
14
15    println!("driver version {}", driver.version);
16    println!("browser version {}", driver.browser_version);
17
18    if !driver.need_download() {
19        println!("no need to update driver");
20        return;
21    }
22
23    println!("updating driver ...");
24
25    match driver.try_download().await {
26        Ok(_) => println!("Download driver successful"),
27        Err(err) => eprintln!("Download driver failed, {}", err),
28    }
29}
Source

pub fn set_connect_timeout(&mut self, timeout: u64) -> &mut Self

Update connect_timeout (ms) for download requests. Default: 5000.

Examples found in repository?
examples/custom_args.rs (line 9)
4async fn main() {
5    let mut driver = ChromeDriver::new();
6    driver
7        .set_driver_path("/usr/local/bin/chromedriver")
8        .set_browser_path("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
9        .set_connect_timeout(2000)
10        .set_timeout(5000)
11        .init()
12        .await
13        .unwrap();
14
15    println!("driver version {}", driver.version);
16    println!("browser version {}", driver.browser_version);
17
18    if !driver.need_download() {
19        println!("no need to update driver");
20        return;
21    }
22
23    println!("updating driver ...");
24
25    match driver.try_download().await {
26        Ok(_) => println!("Download driver successful"),
27        Err(err) => eprintln!("Download driver failed, {}", err),
28    }
29}
Source

pub fn set_timeout(&mut self, timeout: u64) -> &mut Self

Update timeout (ms) for download requests. Default: 5000.

Examples found in repository?
examples/custom_args.rs (line 10)
4async fn main() {
5    let mut driver = ChromeDriver::new();
6    driver
7        .set_driver_path("/usr/local/bin/chromedriver")
8        .set_browser_path("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
9        .set_connect_timeout(2000)
10        .set_timeout(5000)
11        .init()
12        .await
13        .unwrap();
14
15    println!("driver version {}", driver.version);
16    println!("browser version {}", driver.browser_version);
17
18    if !driver.need_download() {
19        println!("no need to update driver");
20        return;
21    }
22
23    println!("updating driver ...");
24
25    match driver.try_download().await {
26        Ok(_) => println!("Download driver successful"),
27        Err(err) => eprintln!("Download driver failed, {}", err),
28    }
29}
Source

pub async fn init(&mut self) -> Result<(), DriverError>

Setup driver & browser version

Examples found in repository?
examples/default_args.rs (line 6)
4async fn main() {
5    let mut driver = ChromeDriver::new();
6    driver.init().await.unwrap();
7
8    println!("driver version {}", driver.version);
9    println!("browser version {}", driver.browser_version);
10
11    if driver.need_download() {
12        driver.try_download().await.unwrap();
13    }
14}
More examples
Hide additional examples
examples/custom_args.rs (line 11)
4async fn main() {
5    let mut driver = ChromeDriver::new();
6    driver
7        .set_driver_path("/usr/local/bin/chromedriver")
8        .set_browser_path("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
9        .set_connect_timeout(2000)
10        .set_timeout(5000)
11        .init()
12        .await
13        .unwrap();
14
15    println!("driver version {}", driver.version);
16    println!("browser version {}", driver.browser_version);
17
18    if !driver.need_download() {
19        println!("no need to update driver");
20        return;
21    }
22
23    println!("updating driver ...");
24
25    match driver.try_download().await {
26        Ok(_) => println!("Download driver successful"),
27        Err(err) => eprintln!("Download driver failed, {}", err),
28    }
29}
Source

pub fn need_download(&self) -> bool

Compare driver & browser version

Examples found in repository?
examples/default_args.rs (line 11)
4async fn main() {
5    let mut driver = ChromeDriver::new();
6    driver.init().await.unwrap();
7
8    println!("driver version {}", driver.version);
9    println!("browser version {}", driver.browser_version);
10
11    if driver.need_download() {
12        driver.try_download().await.unwrap();
13    }
14}
More examples
Hide additional examples
examples/custom_args.rs (line 18)
4async fn main() {
5    let mut driver = ChromeDriver::new();
6    driver
7        .set_driver_path("/usr/local/bin/chromedriver")
8        .set_browser_path("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
9        .set_connect_timeout(2000)
10        .set_timeout(5000)
11        .init()
12        .await
13        .unwrap();
14
15    println!("driver version {}", driver.version);
16    println!("browser version {}", driver.browser_version);
17
18    if !driver.need_download() {
19        println!("no need to update driver");
20        return;
21    }
22
23    println!("updating driver ...");
24
25    match driver.try_download().await {
26        Ok(_) => println!("Download driver successful"),
27        Err(err) => eprintln!("Download driver failed, {}", err),
28    }
29}
Source

pub async fn try_download(&self) -> Result<(), DriverError>

Download Chromedriver

Examples found in repository?
examples/default_args.rs (line 12)
4async fn main() {
5    let mut driver = ChromeDriver::new();
6    driver.init().await.unwrap();
7
8    println!("driver version {}", driver.version);
9    println!("browser version {}", driver.browser_version);
10
11    if driver.need_download() {
12        driver.try_download().await.unwrap();
13    }
14}
More examples
Hide additional examples
examples/custom_args.rs (line 25)
4async fn main() {
5    let mut driver = ChromeDriver::new();
6    driver
7        .set_driver_path("/usr/local/bin/chromedriver")
8        .set_browser_path("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
9        .set_connect_timeout(2000)
10        .set_timeout(5000)
11        .init()
12        .await
13        .unwrap();
14
15    println!("driver version {}", driver.version);
16    println!("browser version {}", driver.browser_version);
17
18    if !driver.need_download() {
19        println!("no need to update driver");
20        return;
21    }
22
23    println!("updating driver ...");
24
25    match driver.try_download().await {
26        Ok(_) => println!("Download driver successful"),
27        Err(err) => eprintln!("Download driver failed, {}", err),
28    }
29}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more