summaryrefslogtreecommitdiff
path: root/src/browser
diff options
context:
space:
mode:
Diffstat (limited to 'src/browser')
-rw-r--r--src/browser/mod.rs16
-rw-r--r--src/browser/web_browser.rs21
2 files changed, 37 insertions, 0 deletions
diff --git a/src/browser/mod.rs b/src/browser/mod.rs
index 7205f27..1675595 100644
--- a/src/browser/mod.rs
+++ b/src/browser/mod.rs
@@ -34,3 +34,19 @@ pub async unsafe fn get_faculties() -> WebDriverResult<Option<HashMap<String, St
Ok(None)
}
+
+pub async unsafe fn select_option(
+ klass: &str,
+ property_name: &str,
+ property_value: &str,
+) -> WebDriverResult<bool> {
+ if let Some(driver) = &WEB_BROWSER {
+ let result = driver
+ .select_option_from_list(klass, property_name, property_value)
+ .await?;
+
+ return Ok(result);
+ }
+
+ Ok(false)
+}
diff --git a/src/browser/web_browser.rs b/src/browser/web_browser.rs
index c7497cf..ffbdc13 100644
--- a/src/browser/web_browser.rs
+++ b/src/browser/web_browser.rs
@@ -114,6 +114,27 @@ impl Browser {
Ok(None)
}
+
+ /// Select an option from a list of select elements
+ pub async fn select_option_from_list(
+ &self,
+ klass: &str,
+ property_name: &str,
+ property_value: &str,
+ ) -> WebDriverResult<bool> {
+ if let Some(_d) = &self.driver {
+ _d.find_element(By::Css(
+ &format!("li.{}[{}='{}']", klass, property_name, property_value).to_owned()[..],
+ ))
+ .await?
+ .click()
+ .await?;
+
+ return Ok(true);
+ }
+
+ Ok(false)
+ }
}
/// The static unsafe variable used to open a web browser