From c14904124c0d3bc13b8f0739eb174ee5aa7c8b50 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Mon, 23 Aug 2021 14:57:59 +0200 Subject: feat: reserve a study hour --- src/browser/mod.rs | 10 ++++++++++ src/browser/web_browser.rs | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'src/browser') diff --git a/src/browser/mod.rs b/src/browser/mod.rs index 4c7ef8e..528849d 100644 --- a/src/browser/mod.rs +++ b/src/browser/mod.rs @@ -72,3 +72,13 @@ pub async unsafe fn get_timetable() -> WebDriverResult WebDriverResult { + if let Some(driver) = &WEB_BROWSER { + let result = driver.select_timetable_row(index).await?; + + return Ok(result); + } + + Ok(false) +} diff --git a/src/browser/web_browser.rs b/src/browser/web_browser.rs index 5a855d5..10dacb7 100644 --- a/src/browser/web_browser.rs +++ b/src/browser/web_browser.rs @@ -188,6 +188,27 @@ impl Browser { Ok(None) } + + // Select the row for the timetable booking + pub async unsafe fn select_timetable_row(&self, index: &str) -> WebDriverResult { + if let Some(_d) = &self.driver { + _d.find_element(By::Css( + &format!("#slotContainerTable tr:nth-child({}) td", index).to_owned()[..], + )) + .await? + .click() + .await?; + thread::sleep(time::Duration::from_millis(2000)); + _d.find_element(By::Css("#partialQuestionYesNoConfirmButton:last-child")) + .await? + .click() + .await?; + + return Ok(true); + } + + Ok(false) + } } /// The static unsafe variable used to open a web browser -- cgit v1.2.3-18-g5258