def open(self):
     self.browser.get(self.url)
     WDW(self.browser, 15)\
         .until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#login_form > .btn-primary")))
     WDW(self.browser, 15)\
         .until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[name='registration_submit']")))
     return self
 def open(self):
     self.browser.get(self.url)
     WDW(self.browser, 15) \
         .until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".form-group > input")))
     WDW(self.browser, 15) \
         .until(EC.element_to_be_clickable((By.CLASS_NAME, "btn-block")))
     return self
Example #3
0
 def open(self):
     self.browser.get(self.url)
     WDW(self.browser, 15)\
         .until(EC.visibility_of((By.CSS_SELECTOR, ".action > h1")))
     WDW(self.browser, 15)\
         .until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".form-group > input")))
     return self
Example #4
0
def getNewsContent(driver):
    WDW(driver, 15).until(EC.presence_of_all_elements_located)
    driver.find_element_by_css_selector('.btn.btn-link').send_keys(Keys.ENTER)
    WDW(driver, 15).until(EC.presence_of_all_elements_located)
    time.sleep(3)
    news_content = driver.find_element_by_xpath(
        "/html/body/div/div[3]/section/div[2]/div[1]/div[4]").text
    return news_content, driver
Example #5
0
 def wait_for_it(self, element_id):
     try:
         (WDW(self.driver, 10).until(
             EC.presence_of_element_located((By.ID, element_id))))
         (WDW(self.driver, 10).until(
             EC.element_to_be_clickable((By.ID, element_id))))
     except Exception as e:
         logging.debug(e)
         logging.info(f'Element id: {element_id}')
Example #6
0
def getMore(search):
    driver.execute_script("window.open('https://google.com')")
    driver.switch_to.window(driver.window_handles[-1])
    try :
        input_element = WDW(driver, 2).until(poel((By.NAME, "q")))
    finally:
        pass
    input_element.send_keys(search)
    input_element.submit()
    try:
        link = WDW(driver, 2).until(poel((By.XPATH, "//div/a/h3")))
    finally:
        link.click()
    try:
        try:
            okay = WDW(driver, 2).until(poel((By.XPATH, '//*[@id="didomi-notice-agree-button"]')))
        finally:
            okay.click()
    except:
        pass
    goalLists = driver.find_elements_by_xpath("//*[contains(@class, 'Scoreboard__goalList')]")

    homeTable = goalLists[0].find_elements_by_xpath("*")
    awayTable = goalLists[1].find_elements_by_xpath("*")
    
    HT = 0
    HC = 0
    HP = 0
    AT = 0
    AC = 0
    AP = 0

    for i in homeTable:
        txt = i.get_attribute('innerText')
        if 'essais' in txt:
            HT = int(txt.split('\n')[0])
        if 'transf' in txt:
            HC = int(txt.split('\n')[0])
        if 'pénali' in txt:
            HP = int(txt.split('\n')[0])

    for i in awayTable:
        txt = i.get_attribute('innerText')
        if 'essais' in txt:
            AT = int(txt.split('\n')[0])
        if 'transf' in txt:
            AC = int(txt.split('\n')[0])
        if 'pénali' in txt:
            AP = int(txt.split('\n')[0])
    
    driver.close()
    driver.switch_to.window(driver.window_handles[0])
    time.sleep(5)
    return (HT, HC, HP, AT, AC, AP)
def test_stepik(browser, link):
    browser.get(f"https://stepik.org/lesson/{link}/step/1")
    textarea_answer = WDW(browser, 10).until(
        EC.presence_of_element_located(
            (By.CSS_SELECTOR, ".string-quiz__textarea")))
    answer = str(math.log(int(time.time())))
    textarea_answer.send_keys(answer)
    submit = WDW(browser, 3).until(
        EC.element_to_be_clickable((By.CSS_SELECTOR, ".submit-submission")))
    submit.click()
    answer = WDW(browser, 10).until(
        EC.presence_of_element_located(
            (By.CSS_SELECTOR, ".smart-hints__hint")))
    assert answer.text == "Correct!"
def test_3_del_definition_group(browser, help):
    # заходим в главное меню регламенты - группы регаламентов
    href = '[href="#/definition_groups"]'
    help.definition(browser, href)

    # Ищем строку ИЗМЕНЕННАЯ ТЕСТОВАЯ ГРУППА РЕГЛАМЕНТОВ
    line_definition = browser.find_elements_by_css_selector(
        '[class="text-pointer"]')
    deleg_definition = browser.find_element_by_xpath(
        '//b[text()="ИЗМЕНЕННАЯ ТЕСТОВАЯ ГРУППА РЕГЛАМЕНТОВ"]'
    )  # ИЗМЕНЕННАЯ ТЕСТОВАЯ ГРУППА РЕГЛАМЕНТОВ"]')
    deleg_definition.click()
    i = 0
    while line_definition[i] != deleg_definition:
        i += 1
        time.sleep(2)
        # browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")

    # удаляем группу регламентов
    selector = '[class="remove-icon text-black"]'
    help.f_selectors(browser, selector, i)

    # подтвердить удаление
    alert = WDW(browser, 10).until(EC.alert_is_present())
    alert.accept()
    time.sleep(1)
    # Проверяем отсутствие измененной тестовой группы регламентов
    xpath = '//*[text() = "ИЗМЕНЕННАЯ ТЕСТОВАЯ ГРУППА РЕГЛАМЕНТОВ"]'
    assert help.check_no_exists_by_xpath(
        browser, xpath), "Тестовая группа регламентов не удалена"
Example #9
0
 def is_disappeared(self, how, what, timeout=4):
     try:
         WDW(self.browser, timeout, 1, TimeoutException)\
             .until_not(EC.presence_of_element_located((how, what)))
     except TimeoutException:
         return False
     return True
Example #10
0
 def _is_element_clickable(self, locator: tuple, timer=5) -> bool:
     return bool(
         WDW(self.driver, timer).until(
             EC.element_to_be_clickable(locator),
             message=f"locator hasn't become clickable "
             f"for {timer} seconds",
         ))
Example #11
0
 def _contains_url(self, url: str, timer=5):
     WDW(self.driver, timer).until(
         EC.url_contains(url),
         message=f"Page with url '{url}' has not been loaded "
         f"for {timer} seconds",
     )
     return self.driver.current_url
 def is_visible(self, locator):
     try:
         element = WDW(self.driver,
                       30).until(EC.visibility_of_element_located(locator))
         return bool(element)
     except TimeoutException:
         return False
Example #13
0
 def _wait_element_present(self, locator: tuple, timer=5):
     WDW(self.driver, timer).until(
         EC.presence_of_element_located(locator),
         message=f"Can't find locator on page "
         f"{self.driver.current_url} for {timer} seconds",
     )
     return self.driver.find_element(*locator)
Example #14
0
def test(link, n):
    try:
        # Открыть страницу http://suninjuly.github.io/explicit_wait2.html
        browser = webdriver.Chrome()
        browser.get(link)

        # Дождаться, когда цена дома уменьшится до $100 (ожидание нужно установить не меньше 12 секунд)
        btn = browser.find_element_by_id("book")
        WDW(browser, 12).until(
            EC.text_to_be_present_in_element((By.ID, "price"), "$100")
        )

        # Нажать на кнопку "Book"
        btn.click()

        # Решить уже известную нам математическую задачу (используйте ранее написанный код) и отправить решение
        x = browser.find_element_by_id("input_value").text
        y = calc(x)

        answer = browser.find_element_by_id("answer")
        answer.send_keys(y)

        submit = browser.find_element_by_id("solve")
        submit.click()

        success_msg(n)
    except Exception as e:
        error_msg(n, traceback.format_exc())
    finally:
        time.sleep(10)
        browser.quit()
Example #15
0
 def expose_dropdown(self, element_id):
     try:
         (WDW(self.driver, 10).until(EC.presence_of_element_located(
             (By.ID, element_id))))
         self.click_link(element_id)
     except Exception as e:
         logging.debug(e)
         logging.info(f'Element id: {element_id}')
Example #16
0
    def wait_element_visible(self, element: Union[Locator, WebElement], timeout: int = None) -> WebElement:
        """Wait for the element visibility."""

        loc_timeout = timeout or self.default_loc_timeout
        el_name = element.name if isinstance(element, Locator) else element.text
        with allure.step(f'Wait "{el_name}" presence'):
            return (
                WDW(self.driver, loc_timeout).until(
                    EC.visibility_of_element_located([element.by, element.value]),
                    message=f"locator {el_name} hasn't become visible for {loc_timeout} seconds",
                )
                if isinstance(element, Locator)
                else WDW(self.driver, loc_timeout).until(
                    EC.visibility_of(element),
                    message=f"locator {el_name} hasn't become visible for {loc_timeout} seconds",
                )
            )
Example #17
0
 def _wait_text_element_in_element(self,
                                   element,
                                   locator: tuple,
                                   timer=5,
                                   text=""):
     WDW(element,
         timer).until(EC.text_to_be_present_in_element(locator, text))
     return element.find_element(*locator)
Example #18
0
def wait_for_new_window(driver: WebDriver, wait_time: int = 10):
    """Wait a new window is opened after some action"""

    tabs = driver.window_handles
    yield
    WDW(driver, wait_time).until(EC.new_window_is_opened(tabs))
    tabs = driver.window_handles
    driver.switch_to.window(tabs[len(tabs) - 1])
Example #19
0
 def wait_and_click_on_cluster_option(self, cluster_name: str, option_locator: Locator):
     """Wait for cluster and click on it"""
     WDW(self.driver, self.default_loc_timeout).until(
         EC.presence_of_element_located([option_locator.by, option_locator.value.format(cluster_name)]),
         message=f"Can't find cluster with name {cluster_name} in dropdown "
         f"on page {self.driver.current_url} "
         f"for {self.default_loc_timeout} seconds",
     ).click()
Example #20
0
 def try_click_toast(self):
     WDW(self.driver, 10).until(
         EC.element_to_be_clickable((By.CLASS_NAME, 'sm-secret-code')))
     time.sleep(.2)
     try:
         self.driver.find_element_by_class_name("sm-secret-code").click()
     except (NoSuchElementException, WebDriverException) as e:
         pass
Example #21
0
def wait_for(me, browser):
    try:
        if me[0] == '.':
            return WDW(browser, 10).until(
                EC.element_to_be_clickable((By.CLASS_NAME, me[1:])))
        elif me[0] == '#':
            return WDW(browser,
                       10).until(EC.element_to_be_clickable((By.ID, me[1:])))
        elif me[0] == '/':
            return WDW(browser,
                       10).until(EC.element_to_be_clickable((By.XPATH, me)))
        else:
            print "We got someting different from classes and ids!"
    except:
        print 'Unexpected error:', sys.exc_info(
        )[0], sys.exc_traceback.tb_lineno
        print "On this page: " + browser.current_url + " we didn't find the me element!"
Example #22
0
    def wait_url_contains_path(self, path: str, timeout: int = None) -> None:
        """Wait url to contain path."""

        url_timeout = timeout or self.default_page_timeout
        WDW(self.driver, url_timeout).until(
            EC.url_contains(path),
            message=f"Page with path '{path}' has not been " f"loaded for {url_timeout} seconds",
        )
Example #23
0
 def _getelement(self, locator: tuple, timer=10):
     return WDW(
         self.driver, timer, ignored_exceptions=self.ignored_exceptions
     ).until(
         EC.presence_of_element_located(locator),
         message=
         f"Can't find locator on page {self.driver.current_url} for {timer} seconds",
     )
Example #24
0
def test_add_to_cart_button_is_displayed(browser):
    browser.get(link)
    # time.sleep(30)
    button = WDW(browser, 5).until(
        EC.visibility_of_all_elements_located(
            (By.CSS_SELECTOR, ".btn-add-to-basket")))
    assert 1 == len(
        button), "Button 'Add to basket' is not found or is not unique button."
Example #25
0
 def startpage(self, checkid=""):
     self.browser.get(self.page)
     if checkid:
         w = WDW(self.browser, 30)
         w.until(EC.presence_of_element_located((By.ID, checkid)))
     else:
         w = None
         time.sleep(30)
     return True
Example #26
0
    def wait_element_clickable(self, locator: Locator, timeout: int = None) -> WebElement:
        """Wait for the element to become clickable."""

        loc_timeout = timeout or self.default_loc_timeout
        with allure.step(f'Wait "{locator.name}" clickable'):
            return WDW(self.driver, loc_timeout).until(
                EC.element_to_be_clickable([locator.by, locator.value]),
                message=f"locator {locator.name} hasn't become clickable for " f"{loc_timeout} seconds",
            )
Example #27
0
def answered(d, question_number):
    wait_variable = WDW(d, wait_time_out)
    answer_element = wait_variable.until(
        EC.presence_of_element_located(
            (By.NAME, 'answer' + str(question_number))))
    if 'Correct.' in answer_element.get_attribute('value'):
        return True
    else:
        return False
Example #28
0
 def _wait_text_element_in_element(element,
                                   locator: tuple,
                                   timer=5,
                                   text=""):
     WDW(element, timer).until(
         EC.text_to_be_present_in_element(locator, text),
         message=f"Can't find text in locator for {timer} seconds",
     )
     return element.find_element(*locator)
Example #29
0
    def find_elements(self, locator: Locator, timeout: int = None) -> [WebElement]:
        """Find elements on current page."""

        loc_timeout = timeout or self.default_loc_timeout
        with allure.step(f'Find elements "{locator.name}" on page'):
            return WDW(self.driver, loc_timeout).until(
                EC.presence_of_all_elements_located([locator.by, locator.value]),
                message=f"Can't find {locator.name} on page " f"{self.driver.current_url} for {loc_timeout} seconds",
            )
Example #30
0
def login(driver, keio_id, keio_pwd):
    driver.get('https://portal.keio.jp/')
    WDW(driver, 15).until(EC.presence_of_all_elements_located)

    driver.find_element_by_id('username').send_keys(keio_id)
    driver.find_element_by_id('password').send_keys(keio_pwd)
    driver.find_element_by_name('_eventId_proceed').send_keys(Keys.ENTER)

    return driver