Ejemplo n.º 1
0
    def updateGameBoardOcr(current_session: webdriver):
        gameBoard = [None] * 9

        # make Screencapture and save
        current_session.get_screenshot_as_file('./img/input.png')

        ocr_functions.getIndividualBoxes()

        # return gameboard
        return
Ejemplo n.º 2
0
def download_image(driver: webdriver, link: str, file_name, output_dir=None):
    """
    Функция осуществляет скачивание изображения по его ссылке
    обязательные аргументы - объект-драйвер, ссылка на изображение,
    и имя файла
    необязательный аргумент - директория, по умолчанию задана текущая
    """
    if output_dir is None:
        output_dir = os.getcwd()
    # переход драйвера по ссылке
    driver.get(link)
    # скачивание картинки как файла
    driver.get_screenshot_as_file(output_dir + os.sep + file_name)
Ejemplo n.º 3
0
    def get_screenshot(self, name: str, driver: webdriver, dictionary_path: str) -> None:
        original_size = driver.get_window_size()
        required_width = driver.execute_script('return document.body.parentNode.scrollWidth')
        required_height = driver.execute_script('return document.body.parentNode.scrollHeight')
        driver.set_window_size(required_width, required_height)

        if not os.path.exists(dictionary_path):
            os.makedirs(dictionary_path)

        t = time.localtime()
        current_time = time.strftime("%H-%M-%S", t)
        path = f"{dictionary_path}/screenshot_{name}_{current_time}.png"
        time.sleep(1)
        driver.get_screenshot_as_file(path)
        time.sleep(1)
        driver.set_window_size(original_size['width'], original_size['height'])
Ejemplo n.º 4
0
def get_price(driver: webdriver) -> Tuple[datetime, str, Set[str]]:
    driver.get(URL)

    WebDriverWait(driver, 10).until(
        EC.presence_of_element_located(
            (By.LINK_TEXT, "Book")  # Button like 'Book' or 'Confirm'
        ))

    # CSS selectors for currency and price elements on page
    currency = driver.find_elements_by_css_selector("p.price_info span")
    prices = driver.find_elements_by_css_selector("p.price_info span.num")

    timestamp = datetime.now()

    driver.get_screenshot_as_file(
        f"{SCREENSHOT_PATH}/ticket-prices_{timestamp.strftime('%d-%m-%Y_%H-%M-%S')}.png"
    )

    return timestamp, currency[0].text, {i.text for i in prices}
Ejemplo n.º 5
0
def test_site(driver: webdriver, image_path: str, url: str, username: str,
              password: str) -> str:
    driver.get(url)

    # Checks if the coming soon title is present
    try:
        coming_soon_title = driver.find_element_by_xpath(
            '//*[@id="seed-csp4-headline"]')
        login_link = driver.find_element_by_xpath(
            "//a[starts-with(@href, 'wp-admin/')]")
        login_link.click()
        username_field = driver.find_element_by_xpath("//*[@id='user_login']")
        username_field.clear()
        username_field.send_keys(username)
        password_field = driver.find_element_by_xpath("//*[@id='user_pass']")
        password_field.clear()
        password_field.send_keys(password)
        submit_button = driver.find_element_by_xpath("//*[@id='wp-submit']")
        submit_button.click()
    except NoSuchElementException:
        pass

    driver.get(url)

    try:
        consent_button = driver.find_element_by_xpath(
            "//a[starts-with(@aria-label, 'dismiss cookie message')]")
        executor = driver
        executor.execute_script("arguments[0].click();", consent_button)
    except NoSuchElementException:
        pass

    id = uuid.uuid4()
    filename = "{}.png".format(id)
    filepath = "{}/{}".format(images_path, filename)

    driver.get_screenshot_as_file(filepath)

    return filename
Ejemplo n.º 6
0
def logIn(driver: webdriver, user_id: str, password: str):
    driver.get("https://lms-kjsce.somaiya.edu/login/index.php")
    login = WebDriverWait(driver, timeout=10).until(
        expected_conditions.element_to_be_clickable(
            (By.CLASS_NAME, "potentialidp")))
    login.find_element_by_class_name("btn").click()
    # time.sleep(1)
    while (True):
        driver.get_screenshot_as_file("screenshot.png")
        driver.find_element_by_id("identifierId").send_keys(user_id)
        driver.find_element_by_id("identifierNext").click()
        time.sleep(2)
        if len(driver.find_elements_by_name("password")) > 0:
            break
        try:
            temp = driver.find_element_by_id("identifierId").get_attribute(
                "outerHTML")
            temp = temp[temp.index("aria-invalid") + 14]
            if temp == 't':
                user_id = input("Invalid mail-id. \nPlease enter mail-id:")
                driver.find_element_by_id("identifierId").clear()
            else:
                print(
                    "Kindly try again. One of the following reasons may be possible for the error:\n1. No internet connection\n2. You have 2-factor authentication enabled for your mail account"
                )
                return False
        except:
            print(
                "Kindly try again. One of the following reasons may be possible for the error:\n1. No internet connection\n2. You have 2-factor authentication enabled for your mail account"
            )
            return False
    while (True):
        WebDriverWait(driver, timeout=10).until(
            expected_conditions.visibility_of_element_located(
                (By.NAME, "password"))).send_keys(password)
        driver.find_element_by_id("passwordNext").click()
        time.sleep(3)
        if 'edu/my' in driver.current_url:
            return True
        try:
            temp = driver.find_element_by_id("password").get_attribute(
                "outerHTML")
            temp = temp[temp.index("aria-invalid") + 14]
            if temp == 't':
                password = getpass.getpass(
                    prompt='Invalid password. Please enter your password: '******'edu/my' in driver.current_url:
                    return True
                return False
        except:
            if 'edu/my' in driver.current_url:
                return True
            driver.get("https://lms-kjsce.somaiya.edu/login/index.php")
            time.sleep(3)
            if '0/h' in driver.current_url:
                return True
            print(
                "Kindly try again. One of the following reasons may be possible for the error:\n1. No internet connection\n2. You have 2-factor authentication enabled for your mail account"
            )
            return False