Ver código fonte

Check form input status, close #1

Sean 4 anos atrás
pai
commit
e12614372d
2 arquivos alterados com 21 adições e 3 exclusões
  1. 20 2
      ocma/connect.py
  2. 1 1
      pyproject.toml

+ 20 - 2
ocma/connect.py

@@ -7,6 +7,7 @@ from urllib.parse import urlparse
 from otppy import OTP
 from selenium import webdriver
 from selenium.common.exceptions import ElementClickInterceptedException
+from selenium.common.exceptions import ElementNotInteractableException
 from selenium.common.exceptions import NoSuchElementException
 from selenium.common.exceptions import StaleElementReferenceException
 from selenium.common.exceptions import TimeoutException
@@ -89,10 +90,15 @@ def _fill_login(driver: webdriver.Firefox, username: str, password: str) -> None
     if not _find_element(driver, By.NAME, USERNAME_INPUT_NAME):
         raise ValueError("Could not find login page!")
 
+    if not _element_interactable(driver, By.NAME, USERNAME_INPUT_NAME):
+        raise ValueError("Could not find username field!")
     driver.find_element(By.NAME, USERNAME_INPUT_NAME).send_keys(username)
+    click_continue(driver)
+
+    if not _element_interactable(driver, By.NAME, PASSWORD_INPUT_NAME):
+        raise ValueError("Could not find password input!")
     driver.find_element(By.NAME, PASSWORD_INPUT_NAME).send_keys(password)
-    click_continue(driver)  # Confirm username
-    click_continue(driver)  # Confirm password
+    click_continue(driver)
 
     on_login_form = lambda: "saml2" in driver.current_url
 
@@ -182,6 +188,18 @@ def _find_element(driver: webdriver.Firefox, by: str, item: str, wait: int = 8)
         return False
 
 
+def _element_interactable(
+    driver: webdriver.Firefox, by: str, item: str, wait: int = 8
+) -> bool:
+    try:
+        w = WebDriverWait(driver, wait)
+        w.until(EC.element_to_be_clickable((by, item)))
+        return True
+
+    except ElementNotInteractableException:
+        return False
+
+
 def _is_on_install_page(driver: webdriver.Firefox) -> None:
     if not _find_element(driver, By.ID, VPN_INSTALL_PAGE_EXCLUSIVE_ELEMENT_ID):
         raise ValueError("Could not find install page!")

+ 1 - 1
pyproject.toml

@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "ocma"
-version = "0.1.3"
+version = "0.1.4"
 description = ""
 authors = ["Sean Blackburn <birdicode@gmail.com>"]
 license = "MIT"