-
Notifications
You must be signed in to change notification settings - Fork 135
Support querying numeric HTML properties from elements::Element::prop()
#289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
johnDeSilencio
wants to merge
8
commits into
jonhoo:main
Choose a base branch
from
johnDeSilencio:feature/support-numeric-properties
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+74
−10
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8f91d11
feat(elements): support querying numeric properties like childElement…
johnDeSilencio 7063371
test(elements): add test case for numeric prop value in the sample page
johnDeSilencio 3fbf333
refactor(element-prop)!: 🔄 return serde_json::Value instead of String…
johnDeSilencio 3e80945
fix(element-html): 🐛 html() method stringifies the return value from …
johnDeSilencio f52ed85
test(element-prop): 🧪 failing test cases
johnDeSilencio 623685f
docs(element-prop): 📖 correct out of date documentation and add new d…
johnDeSilencio c0e34bd
Merge remote-tracking branch 'origin/main' into feature/support-numer…
johnDeSilencio 5499fb2
fix(element-html): 🐛 html() method only returns Ok() when prop() retu…
johnDeSilencio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -223,20 +223,54 @@ impl Element { | |
| /// | ||
| /// `Ok(None)` is returned if the element does not have the given property. | ||
| /// | ||
| /// Boolean properties such as "checked" will be returned as the String "true" or "false". | ||
| /// | ||
| /// See [13.3 Get Element Property](https://www.w3.org/TR/webdriver1/#get-element-property) | ||
| /// of the WebDriver standard. | ||
| /// | ||
| /// [property]: https://www.ecma-international.org/ecma-262/5.1/#sec-8.12.1 | ||
| /// | ||
| /// Example: | ||
| /// | ||
| /// ``` | ||
| /// # use fantoccini::{ClientBuilder, error, Locator}; | ||
| /// # use serde_json::{json, Number}; | ||
| /// # async fn no_search_results() -> Result<(), error::CmdError> { | ||
| /// // Define capabilities of client... | ||
| /// # let capabilities = json!({}) | ||
| /// # .as_object() | ||
| /// # .unwrap() | ||
| /// # .to_owned(); | ||
| /// # | ||
| /// // Create client... | ||
| /// # let client = ClientBuilder::native() | ||
| /// # .capabilities(capabilities) | ||
| /// # .connect("http://127.0.0.1:4444") | ||
| /// # .await.unwrap(); | ||
| /// # | ||
| /// // Perform some kind of search on the website that we don't expect any results from... | ||
| /// | ||
| /// let search_matches = client | ||
| /// .wait() | ||
| /// .for_element(Locator::Css("#search-matches")) | ||
| /// .await?; | ||
| /// | ||
| /// let num_search_matches = search_matches | ||
| /// .prop("childElementCount") | ||
| /// .await? | ||
| /// .expect("expected there to be some value for childElementCount property") | ||
| /// .as_u64() | ||
| /// .expect("expected childElementCount to be an integer value"); | ||
| /// | ||
| /// assert_eq!(num_search_matches, 0); | ||
| /// # | ||
| /// # Ok(()) | ||
| /// # }; | ||
| /// ``` | ||
| #[cfg_attr(docsrs, doc(alias = "Get Element Property"))] | ||
| pub async fn prop(&self, prop: &str) -> Result<Option<String>, error::CmdError> { | ||
| pub async fn prop(&self, prop: &str) -> Result<Option<Json>, error::CmdError> { | ||
| let cmd = WebDriverCommand::GetElementProperty(self.element.clone(), prop.to_string()); | ||
| match self.client.issue(cmd).await? { | ||
| Json::String(v) => Ok(Some(v)), | ||
| Json::Bool(b) => Ok(Some(b.to_string())), | ||
| Json::Null => Ok(None), | ||
| v => Err(error::CmdError::NotW3C(v)), | ||
| v => Ok(Some(v)), | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -336,7 +370,13 @@ impl Element { | |
| #[cfg_attr(docsrs, doc(alias = "outerHTML"))] | ||
| pub async fn html(&self, inner: bool) -> Result<String, error::CmdError> { | ||
| let prop = if inner { "innerHTML" } else { "outerHTML" }; | ||
| Ok(self.prop(prop).await?.unwrap()) | ||
|
|
||
| match self.prop(prop).await? { | ||
| // Requesting `innerHTML` or `outerHTML` should normally return a string | ||
| Some(Json::String(contents)) => Ok(contents), | ||
| Some(res) => Err(error::CmdError::NotW3C(res)), | ||
| _ => Err(error::CmdError::NotW3C(Json::Null)), | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is the most appropriate error variant for the
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm fine with this! |
||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.