Struct thirtyfour_sync::WebElement [−][src]
pub struct WebElement<'a> {
pub element_id: ElementId,
pub session: &'a WebDriverSession,
}
Expand description
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
session: &'a WebDriverSession
Implementations
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.
Get the bounding rectangle for this WebElement.
Get the tag name for this WebElement.
Example:
let elem = driver.find_element(By::Id("button1"))?;
assert_eq!(elem.tag_name()?, "button");
Get the class name for this WebElement.
Example:
let elem = driver.find_element(By::Id("button1"))?;
let class_name_option = elem.class_name()?; // Option<String>
Get the id for this WebElement.
Example:
let elem = driver.find_element(By::Id("button1"))?;
let id_option = elem.id()?; // Option<String>
Get the text contents for this WebElement.
Example:
let elem = driver.find_element(By::Id("button-result"))?;
let text = elem.text()?;
Convenience method for getting the (optional) value attribute of this element.
Get the specified property.
Example:
let bool_value_option = elem.get_property("checked")?; // Option<String>
assert_eq!(bool_value_option, Some("true".to_string()));
let string_value_option = elem.get_property("name")?; // Option<String>
assert_eq!(string_value_option, Some("input2".to_string()));
Get the specified attribute.
Example:
let attribute_option = elem.get_attribute("name")?; // Option<String>
assert_eq!(attribute_option, Some("input2".to_string()));
Get the specified CSS property.
Example:
let css_color = elem.get_css_property("color")?;
assert_eq!(css_color, r"rgba(0, 0, 0, 1)");
Return true if the WebElement is currently selected, otherwise false.
Return true if the WebElement is currently displayed, otherwise false.
Example
let displayed = elem.is_displayed()?;
Return true if the WebElement is currently enabled, otherwise false.
Example
let enabled = elem.is_enabled()?;
Return true if the WebElement is currently clickable (visible and enabled), otherwise false.
Example
let clickable = elem.is_clickable()?;
Return true if the WebElement is currently (still) present and not stale.
NOTE: This method simply queries the tag name in order to determine whether the element is still present.
IMPORTANT: If an element is re-rendered it may be considered stale even though to the user it looks like it is still there.
The recommended way to check for the presence of an element is to simply search for the element again.
Example
let present = elem.is_present()?;
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"))?;
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");
}
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)?;
Take a screenshot of this WebElement and return it as a base64-encoded String.
Take a screenshot of this WebElement and return it as PNG bytes.
Take a screenshot of this WebElement and write it to the specified filename.
Focus this WebElement using JavaScript.
Example:
let elem = driver.find_element(By::Name("input1"))?;
elem.focus()?;
Scroll this element into view using JavaScript.
Example:
let elem = driver.find_element(By::Id("button1"))?;
elem.scroll_into_view()?;
Get the innerHtml property of this element.
Example:
let elem = driver.find_element(By::XPath(r##"//*[@id="button1"]/.."##))?;
let html = elem.inner_html()?;
Get the outerHtml property of this element.
Example:
let elem = driver.find_element(By::XPath(r##"//*[@id="button1"]/.."##))?;
let html = elem.outer_html()?;
Trait Implementations
Return an ElementQuery instance for more executing powerful element queries.
This uses the builder pattern to construct queries that will return one or more elements, depending on the method specified at the end of the chain.
See ElementQuery for more documentation.
Return an ElementWaiter instance for more executing powerful explicit waits.
This uses the builder pattern to construct explicit waits using one of the provided predicates. Or you can provide your own custom predicate if desired.
See ElementWaiter for more documentation.
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
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more