D
D
Damen Damen2017-09-28 14:36:11
Python
Damen Damen, 2017-09-28 14:36:11

How to get rid of unnecessary slips?

Is there any universal option how to get rid of time.sleep()? tried wait's but something didn't work

def test_fav_add(self):
        time.sleep(4)
        fav = self.driver.find_elements_by_class_name('fa-star-o')
        choice(fav).click()
        time.sleep(4)
        self.driver.execute_script("window.scrollTo(0, 0);")
        big_star_el = self.driver.find_element_by_xpath(big_star)
        big_star_el.click()
        time.sleep(3)
        all_fav = self.driver.find_elements_by_xpath('//*/div[1]/div[3]/ul/li[2]/i')
        time.sleep(2)
        for i in all_fav:
            i.click()
        self.driver.find_element_by_xpath(big_star).click()
        time.sleep(2)
        self.driver.find_element_by_xpath(big_star).click()
        time.sleep(2)
        self.assertEqual(self.driver.find_element_by_xpath(no_posts).text, 'У Вас нет избранных сообщений')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2017-09-28
@uWotM8

def find_by_someID(driver):
    element = driver.find_element(By.ID, 'someID')
    return element if element else False

inp = WebDriverWait(driver, 5).until(find_by_someID)
# что-то делаем с найденным inp

D
Dmitry Eremin, 2017-09-28
@EreminD

what do you mean it didn't work?
make elements wait and click on them

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question