How to use the instapy.util.explicit_wait function in instapy

To help you get started, we’ve selected a few instapy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Instagram-Tools / bot / instapy / comment_util.py View on Github external
def get_comment_input(browser, logger):
    comment_input = explicit_wait(browser, "VOEL", ['//textarea[@placeholder = "Add a comment…"]', "XPath"], logger, 7, False)

    if not comment_input:
        comment_input = explicit_wait(browser, "VOEL", ['//input[@placeholder = "Add a comment…"]', "XPath"], logger, 7, False)

    return comment_input
github Instagram-Tools / bot / instapy / login_util.py View on Github external
def dismiss_notification_offer(browser, logger):
    """ Dismiss 'Turn on Notifications' offer on session start """
    offer_elem_loc = read_xpath(dismiss_notification_offer.__name__, "offer_elem_loc")
    dismiss_elem_loc = read_xpath(
        dismiss_notification_offer.__name__, "dismiss_elem_loc"
    )

    # wait a bit and see if the 'Turn on Notifications' offer rises up
    offer_loaded = explicit_wait(
        browser, "VOEL", [offer_elem_loc, "XPath"], logger, 4, False
    )

    if offer_loaded:
        dismiss_elem = browser.find_element_by_xpath(dismiss_elem_loc)
        click_element(browser, dismiss_elem)
github Instagram-Tools / bot / instapy / login_util.py View on Github external
def dismiss_get_app_offer(browser, logger):
    """ Dismiss 'Get the Instagram App' page after a fresh login """
    offer_elem = read_xpath(dismiss_get_app_offer.__name__, "offer_elem")
    dismiss_elem = read_xpath(dismiss_get_app_offer.__name__, "dismiss_elem")

    # wait a bit and see if the 'Get App' offer rises up
    offer_loaded = explicit_wait(
        browser, "VOEL", [offer_elem, "XPath"], logger, 5, False
    )

    if offer_loaded:
        dismiss_elem = browser.find_element_by_xpath(dismiss_elem)
        click_element(browser, dismiss_elem)
github Instagram-Tools / bot / instapy / comment_util.py View on Github external
# check if there are any comments in the post
    comments_count, msg = get_comments_count(browser, logger)
    if not comments_count:
        logger.info(msg)
        return None

    # get comments & commenters information
    comments_block_XPath = "//div/div/h3/../../../.."  # efficient location
    # path
    like_button_full_XPath = "//div/span/button/span[@aria-label='Like']"
    unlike_button_full_XPath = "//div/span/button/span[@aria-label='Unlike']"

    comments = []
    commenters = []
    # wait for page fully load [IMPORTANT!]
    explicit_wait(browser, "PFL", [], logger, 10)

    try:
        all_comment_like_buttons = browser.find_elements_by_xpath(
            like_button_full_XPath)
        if all_comment_like_buttons:
            comments_block = browser.find_elements_by_xpath(
                comments_block_XPath)
            for comment_line in comments_block:
                commenter_elem = comment_line.find_element_by_xpath('//h3/a')
                commenter = extract_text_from_element(commenter_elem)
                if (commenter and
                        commenter not in [owner, poster, ignore_users] and
                        commenter not in commenters):
                    commenters.append(commenter)
                else:
                    continue
github Instagram-Tools / bot / instapy / login_util.py View on Github external
update_activity(
            browser,
            action=None,
            state=error_alert.text,
            logfolder=logfolder,
            logger=logger,
        )
        return False
    except NoSuchElementException:
        pass

    if "instagram.com/accounts/onetap" in browser.current_url:
        browser.get("https://instagram.com")

    # wait until page fully load
    explicit_wait(browser, "PFL", [], logger, 5)

    # Check if user is logged-in (If there's two 'nav' elements)
    nav = browser.find_elements_by_xpath(read_xpath(login_user.__name__, "nav"))
    if len(nav) == 2:
        # create cookie for username
        pickle.dump(
            browser.get_cookies(),
            open("{0}{1}_cookie.pkl".format(logfolder, username), "wb"),
        )
        return True
    else:
        return False
github Instagram-Tools / bot / instapy / unfollow_util.py View on Github external
try:
            follow_button = browser.find_element_by_xpath(
                read_xpath(get_following_status.__name__, "follow_span_XP_following")
            )
            return "Following", follow_button
        except:
            return "UNAVAILABLE", None
    follow_button = explicit_wait(
        browser, "VOEL", [follow_button_XP, "XPath"], logger, 7, False
    )

    if not follow_button:
        browser.execute_script("location.reload()")
        update_activity(browser, state=None)

        follow_button = explicit_wait(
            browser, "VOEL", [follow_button_XP, "XPath"], logger, 14, False
        )
        if not follow_button:
            # cannot find the any of the expected buttons
            logger.error(failure_msg.format(person.encode("utf-8")))
            return None, None

    # get follow status
    following_status = follow_button.text

    return following_status, follow_button
github Instagram-Tools / bot / instapy / comment_util.py View on Github external
def get_comment_input(browser, logger):
    comment_input = explicit_wait(browser, "VOEL", ['//textarea[@placeholder = "Add a comment…"]', "XPath"], logger, 7, False)

    if not comment_input:
        comment_input = explicit_wait(browser, "VOEL", ['//input[@placeholder = "Add a comment…"]', "XPath"], logger, 7, False)

    return comment_input