MCPcopy
hub / github.com/InstaPy/InstaPy / explicit_wait

Function explicit_wait

instapy/util.py:1792–1858  ·  view source on GitHub ↗

Explicitly wait until expected condition validates :param browser: webdriver instance :param track: short name of the expected condition :param ec_params: expected condition specific parameters - [param1, param2] :param logger: the logger instance

(browser, track, ec_params, logger, timeout=35, notify=True)

Source from the content-addressed store, hash-verified

1790
1791
1792def explicit_wait(browser, track, ec_params, logger, timeout=35, notify=True):
1793 """
1794 Explicitly wait until expected condition validates
1795
1796 :param browser: webdriver instance
1797 :param track: short name of the expected condition
1798 :param ec_params: expected condition specific parameters - [param1, param2]
1799 :param logger: the logger instance
1800 """
1801 # list of available tracks:
1802 # <https://seleniumhq.github.io/selenium/docs/api/py/webdriver_support/
1803 # selenium.webdriver.support.expected_conditions.html>
1804
1805 if not isinstance(ec_params, list):
1806 ec_params = [ec_params]
1807
1808 # find condition according to the tracks
1809 condition = None
1810 ec_name = None
1811
1812 if track == "VOEL":
1813 elem_address, find_method = ec_params
1814 ec_name = "visibility of element located"
1815
1816 find_by = (
1817 By.XPATH
1818 if find_method == "XPath"
1819 else By.CSS_SELECTOR
1820 if find_method == "CSS"
1821 else By.CLASS_NAME
1822 )
1823 locator = (find_by, elem_address)
1824 condition = ec.visibility_of_element_located(locator)
1825
1826 elif track == "TC":
1827 expect_in_title = ec_params[0]
1828 ec_name = "title contains '{}' string".format(expect_in_title)
1829
1830 condition = ec.title_contains(expect_in_title)
1831
1832 elif track == "PFL":
1833 ec_name = "page fully loaded"
1834 condition = lambda browser: browser.execute_script(
1835 "return document.readyState"
1836 ) in ["complete" or "loaded"]
1837
1838 elif track == "SO":
1839 ec_name = "staleness of"
1840 element = ec_params[0]
1841
1842 condition = ec.staleness_of(element)
1843
1844 # generic wait block
1845 try:
1846 wait = WebDriverWait(browser, timeout)
1847 result = wait.until(condition)
1848
1849 except TimeoutException:

Callers 11

get_comments_on_postFunction · 0.85
verify_commented_imageFunction · 0.85
login_userFunction · 0.85
dismiss_get_app_offerFunction · 0.85
dismiss_save_informationFunction · 0.85
accept_igcookie_dialogueFunction · 0.85
get_page_titleFunction · 0.85
like_commentFunction · 0.85
get_following_statusFunction · 0.85

Calls 1

execute_scriptMethod · 0.80

Tested by

no test coverage detected