From 5ddacf8e8131bacbcbd360b24c4c45b5380678ee Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 5 Aug 2021 20:33:14 +0200 Subject: feat: get spaces of a faculty --- src/browser/web_browser.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/browser/web_browser.rs') diff --git a/src/browser/web_browser.rs b/src/browser/web_browser.rs index ffbdc13..f799866 100644 --- a/src/browser/web_browser.rs +++ b/src/browser/web_browser.rs @@ -115,6 +115,38 @@ impl Browser { Ok(None) } + /// Get all spaces for booking and return an `HashMap` when `key` is the + /// key for that space inside the `select` tag and `value` is just the text of the option. + pub async fn spaces(&self) -> WebDriverResult>> { + if let Some(_d) = &self.driver { + thread::sleep(time::Duration::from_millis(1000)); + + _d.find_element(By::Css( + "span[aria-labelledby='select2-spaceSelector-container']", + )) + .await? + .click() + .await?; + + let list_elements = _d + .find_elements(By::Css("#select2-spaceSelector-results li")) + .await?; + + let mut spaces_ids = HashMap::::new(); + + for i in list_elements { + spaces_ids.insert( + i.get_attribute("data-select2-id").await.unwrap().unwrap(), + i.text().await.unwrap(), + ); + } + + return Ok(Some(spaces_ids)); + } + + Ok(None) + } + /// Select an option from a list of select elements pub async fn select_option_from_list( &self, -- cgit v1.2.3-18-g5258