R
R
rmfalx2017-08-28 12:55:31
Python
rmfalx, 2017-08-28 12:55:31

How to use wait instead of sleep?

How to use weights correctly? Please provide a code example.
For example, I have such a test of the login page, how can I use weights in it correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vlad Grigoriev, 2017-08-28
@rmfalx

from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By


def get_element(self, path_type, element_path, custom_time_out=None,):
    """
    :param path_type: тип локатора
    :param element_path: путь элемента
    :return:
    """
    __type = {
        'xpath': By.XPATH,
        'css': By.CSS_SELECTOR,
        'id': By.ID,
        'class': By.CLASS_NAME
    }
    if custom_time_out is not None:
        time_out = custom_time_out
    else:
        time_out = self.time_out

    return WebDriverWait(self.driver, time_out).until(expected_conditions.presence_of_element_located((__type.get(path_type), element_path)))

D
Damen Damen, 2017-09-26
@uWotM8

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(self.driver, 10)
 element = wait.until(EC.element_to_be_clickable(
            (By.CLASS_NAME, 'some class')))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question