refactoring

This commit is contained in:
frankknoll
2022-11-22 13:22:00 +01:00
parent 80e94c92d4
commit d94869181b
5 changed files with 164 additions and 194 deletions

27
src/WebDriver.py Normal file
View File

@@ -0,0 +1,27 @@
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
def _getOptions(downloadDir, isHeadless):
options = Options()
options.headless = isHeadless
options.add_experimental_option("prefs", {"download.default_directory" : downloadDir})
return options
def getWebDriver(downloadDir, isHeadless):
return webdriver.Chrome(
service = ChromeService(executable_path = ChromeDriverManager().install()),
options = _getOptions(downloadDir, isHeadless))
def saveCaptchaImageAs(driver, captchaImageFile):
captchaImage = driver.find_element(By.CSS_SELECTOR, "img[src='captchaImage']")
with open(captchaImageFile, 'wb') as file:
file.write(captchaImage.screenshot_as_png)
def existsElementWithId(driver, id):
return len(driver.find_elements(By.ID, id)) > 0
def isCaptchaSolved(driver):
return not existsElementWithId(driver, "wordverify")