pub struct Driver(/* private fields */);
Implementations§
Source§impl Driver
impl Driver
Sourcepub async fn new(
webdriver_url: &str,
user_agent: Option<String>,
) -> Result<Self>
pub async fn new( webdriver_url: &str, user_agent: Option<String>, ) -> Result<Self>
Create a new webdriver session on the specified server
Sourcepub async fn goto<'a>(&'a self, url: &'a str) -> Result<()>
pub async fn goto<'a>(&'a self, url: &'a str) -> Result<()>
Navigate directly to the given URL.
Sourcepub async fn current_url(&self) -> Result<Url>
pub async fn current_url(&self) -> Result<Url>
Retrieve the currently active URL for this session.
Sourcepub async fn switch_to_frame(&self, frame: WebElement) -> Result<()>
pub async fn switch_to_frame(&self, frame: WebElement) -> Result<()>
Switch the focus to the frame contained in Element
Sourcepub async fn switch_to_parent_frame(&self) -> Result<()>
pub async fn switch_to_parent_frame(&self) -> Result<()>
Switch the focus to this frame’s parent frame
Sourcepub async fn switch_to_window(&self, window: String) -> Result<()>
pub async fn switch_to_window(&self, window: String) -> Result<()>
Switch the focus to the window identified by handle
Sourcepub async fn execute(&self, script: String, args: Vec<Value>) -> Result<Value>
pub async fn execute(&self, script: String, args: Vec<Value>) -> Result<Value>
Execute the given JavaScript script
in the current browser session.
args
is available to the script inside the arguments
array. Since Element
implements ToJson
, you can also
provide serialized Element
s as arguments, and they will
correctly serialize to DOM elements on the other side.
Wait for the page to navigate to a new URL before proceeding.
If the current
URL is not provided, self.current_url()
will be used. Note however that this introduces a race
condition: the browser could finish navigating before we
call current_url()
, which would lead to an eternal wait.
Sourcepub async fn find(
&self,
locator: Locator,
root: Option<WebElement>,
) -> Result<WebElement>
pub async fn find( &self, locator: Locator, root: Option<WebElement>, ) -> Result<WebElement>
Starting from the document root, find the first element on the page that matches the specified selector.
pub async fn find_all( &self, locator: Locator, root: Option<WebElement>, ) -> Result<Vec<WebElement>>
Sourcepub async fn wait_for_find(
&self,
search: Locator,
root: Option<WebElement>,
) -> Result<WebElement>
pub async fn wait_for_find( &self, search: Locator, root: Option<WebElement>, ) -> Result<WebElement>
Wait for the specified element(s) to appear on the page
Sourcepub async fn wait_for_find_all(
&self,
search: Locator,
root: Option<WebElement>,
) -> Result<Vec<WebElement>>
pub async fn wait_for_find_all( &self, search: Locator, root: Option<WebElement>, ) -> Result<Vec<WebElement>>
Wait for the specified element(s) to appear on the page
Sourcepub async fn attr(
&self,
eid: WebElement,
attribute: String,
) -> Result<Option<String>>
pub async fn attr( &self, eid: WebElement, attribute: String, ) -> Result<Option<String>>
Look up an attribute value for this element by name.
Sourcepub async fn prop(
&self,
eid: WebElement,
prop: String,
) -> Result<Option<String>>
pub async fn prop( &self, eid: WebElement, prop: String, ) -> Result<Option<String>>
Look up a DOM property for this element by name.
Sourcepub async fn text(&self, eid: WebElement) -> Result<String>
pub async fn text(&self, eid: WebElement) -> Result<String>
Retrieve the text contents of this elment.
Sourcepub async fn html(&self, eid: WebElement, inner: bool) -> Result<String>
pub async fn html(&self, eid: WebElement, inner: bool) -> Result<String>
Retrieve the HTML contents of this element. if inner is true,
also return the wrapping nodes html. Note: this is the same as
calling prop("innerHTML")
or prop("outerHTML")
.
Sourcepub async fn click(&self, eid: WebElement) -> Result<()>
pub async fn click(&self, eid: WebElement) -> Result<()>
Click on this element
Sourcepub async fn scroll_into_view(&self, eid: WebElement) -> Result<()>
pub async fn scroll_into_view(&self, eid: WebElement) -> Result<()>
Scroll this element into view
Sourcepub async fn follow(&self, eid: WebElement) -> Result<()>
pub async fn follow(&self, eid: WebElement) -> Result<()>
Follow the href
target of the element matching the given CSS
selector without causing a click interaction.
Sourcepub async fn set_by_name(
&self,
eid: WebElement,
name: String,
value: String,
) -> Result<()>
pub async fn set_by_name( &self, eid: WebElement, name: String, value: String, ) -> Result<()>
Set the value
of the input element named name
which is a child of eid
Sourcepub async fn submit(&self, eid: WebElement) -> Result<()>
pub async fn submit(&self, eid: WebElement) -> Result<()>
Submit the form specified by eid
with the first submit button
Sourcepub async fn submit_with(&self, eid: WebElement, button: Locator) -> Result<()>
pub async fn submit_with(&self, eid: WebElement, button: Locator) -> Result<()>
Submit the form eid
using the button matched by the given selector.
Sourcepub async fn submit_using(
&self,
eid: WebElement,
button_label: String,
) -> Result<()>
pub async fn submit_using( &self, eid: WebElement, button_label: String, ) -> Result<()>
Submit this form using the form submit button with the given label (case-insensitive).
Sourcepub async fn submit_direct(&self, eid: WebElement) -> Result<()>
pub async fn submit_direct(&self, eid: WebElement) -> Result<()>
Submit this form directly, without clicking any buttons.
This can be useful to bypass forms that perform various magic when the submit button is clicked, or that hijack click events altogether.
Note that since no button is actually clicked, the
name=value
pair for the submit button will not be
submitted. This can be circumvented by using submit_sneaky
instead.
Sourcepub async fn submit_sneaky(
&self,
eid: WebElement,
field: String,
value: String,
) -> Result<()>
pub async fn submit_sneaky( &self, eid: WebElement, field: String, value: String, ) -> Result<()>
Submit this form directly, without clicking any buttons, and with an extra field.
Like submit_direct
, this method will submit this form
without clicking a submit button. However, it will also
inject a hidden input element on the page that carries the
given field=value
mapping. This allows you to emulate the
form data as it would have been if the submit button was
indeed clicked.