How to use the instapy.util.click_element 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 / unfollow_util.py View on Github external
"--> Couldn't follow '{}'!\t~{}".format(user_name, failure_msg)
            )
            return False, following_status

        elif following_status is None:
            sirens_wailing, emergency_state = emergency_exit(browser, login, logger)
            if sirens_wailing is True:
                return False, emergency_state

            else:
                logger.warning(
                    "--> Couldn't unfollow '{}'!\t~unexpected failure".format(user_name)
                )
                return False, "unexpected failure"
    elif track == "dialog":
        click_element(browser, button)
        sleep(3)

    # general tasks after a successful follow
    logger.info("--> Followed '{}'!".format(user_name.encode("utf-8")))
    Event().followed(user_name)
    update_activity(
        browser, action="follows", state=None, logfolder=logfolder, logger=logger
    )

    # get user ID to record alongside username
    user_id = get_user_id(browser, track, user_name, logger)

    logtime = datetime.now().strftime("%Y-%m-%d %H:%M")
    log_followed_pool(login, user_name, logger, logfolder, logtime, user_id)

    follow_restriction("write", user_name, None, logger)
github Instagram-Tools / bot / instapy / unfollow_util.py View on Github external
return False, following_status

        elif following_status is None:
            sirens_wailing, emergency_state = emergency_exit(browser, username, logger)
            if sirens_wailing is True:
                return False, emergency_state

            else:
                logger.warning(
                    "--> Couldn't unfollow '{}'!\t~unexpected failure".format(person)
                )
                return False, "unexpected failure"
    elif track == "dialog":
        # Method of unfollowing from a dialog box

        click_element(browser, button)
        sleep(4)  # TODO: use explicit wait here
        confirm_unfollow(browser)

    # general tasks after a successful unfollow
    logger.info("--> Unfollowed '{}'!".format(person))
    Event().unfollowed(person)
    update_activity(
        browser, action="unfollows", state=None, logfolder=logfolder, logger=logger
    )
    post_unfollow_cleanup(
        "successful", username, person, relationship_data, person_id, logger, logfolder
    )

    # get the post-unfollow delay time to sleep
    naply = get_action_delay("unfollow")
    sleep(naply)
github Instagram-Tools / bot / instapy / unfollow_util.py View on Github external
break

        try:
            view_more_button = browser.find_element_by_xpath(
                read_xpath(get_follow_requests.__name__, "view_more_button")
            )
        except NoSuchElementException:
            view_more_button_exist = False

        if view_more_button_exist:
            logger.info(
                "Found '{}' outgoing follow requests, Going to ask for more...".format(
                    len(list_of_users)
                )
            )
            click_element(browser, view_more_button)
            view_more_clicks += 1

    users_to_unfollow = []

    for user in list_of_users:
        users_to_unfollow.append(user.text)
        if len(users_to_unfollow) == amount:
            break

    logger.info(
        "Found '{}' outgoing follow requests '{}'".format(
            len(users_to_unfollow), users_to_unfollow
        )
    )

    return users_to_unfollow
github Instagram-Tools / bot / instapy / unfollow_util.py View on Github external
def confirm_unfollow(browser):
    """ Deal with the confirmation dialog boxes during an unfollow """
    attempt = 0

    while attempt < 3:
        try:
            attempt += 1
            button_xp = read_xpath(
                confirm_unfollow.__name__, "button_xp"
            )  # "//button[contains(
            # text(), 'Unfollow')]"
            unfollow_button = browser.find_element_by_xpath(button_xp)

            if unfollow_button.is_displayed():
                click_element(browser, unfollow_button)
                sleep(2)
                break

        except (ElementNotVisibleException, NoSuchElementException) as exc:
            # prob confirm dialog didn't pop up
            if isinstance(exc, ElementNotVisibleException):
                break

            elif isinstance(exc, NoSuchElementException):
                sleep(1)
github Instagram-Tools / bot / instapy / story_util.py View on Github external
time.sleep(2)
                        if index == 1:
                            try:
                                next_elem = browser.find_element_by_xpath(
                                    read_xpath(watch_story.__name__, "next_first")
                                )
                            except NoSuchElementException:
                                continue
                        else:
                            try:
                                next_elem = browser.find_element_by_xpath(
                                    read_xpath(watch_story.__name__, "next")
                                )
                            except NoSuchElementException:
                                continue
                        click_element(browser, next_elem)
                        reels_cnt += 1
                        index += 1

            return {"status": "ok", "reels_cnt": reels_cnt}
    else:
        return {"status": "not_ok", "reels_cnt": 0}
github Instagram-Tools / bot / instapy / unfollow_util.py View on Github external
elif allFollowing is True:
        # FIXME: this is not working since last get_users_through_dialog_with_graphql update,
        # now we're using graphql, the dialog is not required anymore, and
        # get_users_through_dialog_with_graphql function will return two values
        # (have a look on how get_given_user_followers is using it)
        logger.info("Unfollowing the users you are following")
        logger.warn("all Following option is not working at the moment, leaving...")
        return 0

        # unfollow from profile
        try:
            following_link = browser.find_elements_by_xpath(
                read_xpath(unfollow.__name__, "following_link")
            )

            click_element(browser, following_link[0])
            # update server calls
            update_activity(browser, state=None)
        except BaseException as e:
            logger.error("following_link error {}".format(str(e)))
            return 0

        # scroll down the page to get sufficient amount of usernames
        get_users_through_dialog_with_graphql(
            browser,
            None,
            username,
            amount,
            allfollowing,
            False,
            None,
            None,
github Instagram-Tools / bot / instapy / commenters_util.py View on Github external
)
        comments = comment_list.find_elements_by_tag_name(
            read_xpath(extract_post_info.__name__, "comments")
        )

        if len(comments) > 1:
            # load hidden comments
            more_comments = 0

            while " comments" in comments[1].text:
                more_comments += 1
                print("loading more comments.")
                load_more_comments_element = browser.find_element_by_xpath(
                    read_xpath(extract_post_info.__name__, "load_more_comments_element")
                )
                click_element(browser, load_more_comments_element)
                # comment_list = post.find_element_by_tag_name('ul')
                comments = comment_list.find_elements_by_tag_name("li")

                if more_comments > 10:
                    print("Won't load more than that, moving on..")
                    break

            # if post autor didnt write description, more comments text is
            # in first comment
            if more_comments == 0:
                while " comments" in comments[0].text:
                    more_comments += 1
                    print("loading more comments.")
                    load_more_comments_element = browser.find_element_by_xpath(
                        read_xpath(
                            extract_post_info.__name__, "load_more_comments_element_alt"