[−][src]Struct thirtyfour::sync::prelude::WebElement
The WebElement struct encapsulates a single element on a page.
WebElement structs are generally not constructed manually, but rather they are returned from a 'find_element()' operation using a WebDriver.
Example:
let elem = driver.find_element(By::Id("input-result"))?;
You can also search for a child element of another element as follows:
let elem = driver.find_element(By::Css("div[data-section='section-buttons']"))?; let child_elem = elem.find_element(By::Tag("button"))?;
Elements can be clicked using the click()
method, and you can send
input to an element using the send_keys()
method.
Fields
element_id: ElementId
Implementations
impl<'a> WebElement<'a>
[src]
pub fn new(driver: WebDriverSession<'a>, element_id: ElementId) -> Self
[src]
Create a new WebElement struct.
Typically you would not call this directly. WebElement structs are usually constructed by calling one of the find_element*() methods either on WebDriver or another WebElement.
pub fn rect(&self) -> WebDriverResult<ElementRect>
[src]
Get the bounding rectangle for this WebElement.
pub fn tag_name(&self) -> WebDriverResult<String>
[src]
Get the tag name for this WebElement.
Example:
let elem = driver.find_element(By::Id("button1"))?; assert_eq!(elem.tag_name()?, "button");
pub fn class_name(&self) -> WebDriverResult<String>
[src]
Get the class name for this WebElement.
Example:
let elem = driver.find_element(By::Id("button1"))?; let class_name = elem.class_name()?;
pub fn text(&self) -> WebDriverResult<String>
[src]
Get the text contents for this WebElement.
Example:
let elem = driver.find_element(By::Id("button-result"))?; let text = elem.text()?;
pub fn value(&self) -> WebDriverResult<String>
[src]
Convenience method for getting the value attribute of this element.
pub fn click(&self) -> WebDriverResult<()>
[src]
pub fn clear(&self) -> WebDriverResult<()>
[src]
pub fn get_property(&self, name: &str) -> WebDriverResult<String>
[src]
Get the specified property.
Example:
let bool_value = elem.get_property("checked")?; assert_eq!(bool_value, "true"); let string_value = elem.get_property("name")?; assert_eq!(string_value, "input2");
pub fn get_attribute(&self, name: &str) -> WebDriverResult<String>
[src]
Get the specified attribute.
Example:
let attribute = elem.get_attribute("name")?; assert_eq!(attribute, "input2");
pub fn get_css_property(&self, name: &str) -> WebDriverResult<String>
[src]
Get the specified CSS property.
Example:
let css_color = elem.get_css_property("color")?; assert_eq!(css_color, r"rgba(0, 0, 0, 1)");
pub fn is_selected(&self) -> WebDriverResult<bool>
[src]
Return true if the WebElement is currently selected, otherwise false.
pub fn is_enabled(&self) -> WebDriverResult<bool>
[src]
Return true if the WebElement is currently enabled, otherwise false.
pub fn find_element(&self, by: By) -> WebDriverResult<WebElement>
[src]
Search for a child element of this WebElement using the specified selector.
Example:
let elem = driver.find_element(By::Css("div[data-section='section-buttons']"))?; let child_elem = elem.find_element(By::Tag("button"))?;
pub fn find_elements(&self, by: By) -> WebDriverResult<Vec<WebElement>>
[src]
Search for all child elements of this WebElement that match the specified selector.
Example:
let elem = driver.find_element(By::Css("div[data-section='section-buttons']"))?; let child_elems = elem.find_elements(By::Tag("button"))?; for child_elem in child_elems { assert_eq!(child_elem.tag_name()?, "button"); }
pub fn send_keys<S>(&self, keys: S) -> WebDriverResult<()> where
S: Into<TypingData>,
[src]
S: Into<TypingData>,
Send the specified input.
Example:
You can specify anything that implements Into<TypingData>
. This
includes &str and String.
elem.send_keys("selenium")?;
You can also send special key combinations like this:
elem.send_keys("selenium")?; elem.send_keys(Keys::Control + "a")?; elem.send_keys(TypingData::from("thirtyfour") + Keys::Enter)?;
pub fn screenshot_as_base64(&self) -> WebDriverResult<String>
[src]
Take a screenshot of this WebElement and return it as a base64-encoded String.
pub fn screenshot_as_png(&self) -> WebDriverResult<Vec<u8>>
[src]
Take a screenshot of this WebElement and return it as PNG bytes.
pub fn screenshot(&self, path: &Path) -> WebDriverResult<()>
[src]
Take a screenshot of this WebElement and write it to the specified filename.
pub fn focus(&self) -> WebDriverResult<()>
[src]
Focus this WebElement using JavaScript.
Example:
let elem = driver.find_element(By::Name("input1"))?; elem.focus()?;
pub fn scroll_into_view(&self) -> WebDriverResult<()>
[src]
Scroll this element into view using JavaScript.
Example:
let elem = driver.find_element(By::Id("button1"))?; elem.scroll_into_view()?;
Trait Implementations
impl<'a> Clone for WebElement<'a>
[src]
fn clone(&self) -> WebElement<'a>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a> Debug for WebElement<'a>
[src]
impl<'a> Display for WebElement<'a>
[src]
impl<'a> Serialize for WebElement<'a>
[src]
Auto Trait Implementations
impl<'a> !RefUnwindSafe for WebElement<'a>
impl<'a> Send for WebElement<'a>
impl<'a> Sync for WebElement<'a>
impl<'a> Unpin for WebElement<'a>
impl<'a> !UnwindSafe for WebElement<'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, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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>,