# Buggy code
def interact_user_followers(self, usernames, amount=10, random=False):
    userToInteract = []
    if not isinstance(usernames, list):
        usernames = [usernames]
    try:
        for user in usernames:
            userToInteract += get_given_user_followers(
                self.browser,
                user,
                amount,
                self.dont_include,
                self.username,
                self.follow_restrict,
                random,
            )
    except (TypeError, RuntimeWarning) as err:
        if type(err) == RuntimeWarning:
            print("Warning: {} , stopping follow_users".format(err))
            self.logFile.write("Warning: {} , stopping follow_users\n".format(err))

            return self
        else:
            print("Sorry, an error occured: {}".format(err))
            self.logFile.write("Sorry, an error occured: {}\n".format(err))
            self.aborting = True

            return self

    print("--> Users: {}".format(len(userToInteract)))
    print("")
    userToInteract = sample(
        userToInteract,
        int(ceil(self.user_interact_percentage * len(userToInteract) / 100)),
    )
    self.like_by_users(
        userToInteract,
        self.user_interact_amount,
        self.user_interact_random,
        self.user_interact_media,
    )

    return self


# Traceback (selenium.common.exceptions.NoSuchElementException)
Logged in successfully!
Traceback (most recent call last):
File "test4_instapy.py", line 24, in <module>
session.interact_user_followers(['User1'], amount=12, random=True)
File "/virt_uni/InstaPy/instapy/instapy.py", line 849, in interact_user_followers
userToInteract += get_given_user_followers(self.browser, user, amount, self.dont_include, self.username, self.follow_restrict, random)
File "/virt_uni/InstaPy/instapy/unfollow_util.py", line 327, in get_given_user_followers
allfollowing = formatNumber(browser.find_element_by_xpath("//li[2]/a/span").text)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 293, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 752, in find_element
'value': value})['value']
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//li[2]/a/span"}
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 3.16.0-4-amd64 x86_64)

# Fixed code
def interact_user_followers(self, usernames, amount=10, random=False):
    userToInteract = []
    if not isinstance(usernames, list):
        usernames = [usernames]
    try:
        for user in usernames:
            user = get_given_user_followers(
                self.browser,
                user,
                amount,
                self.dont_include,
                self.username,
                self.follow_restrict,
                random,
            )
            if type(user) is list:
                userToInteract += user
    except (TypeError, RuntimeWarning) as err:
        if type(err) == RuntimeWarning:
            print("Warning: {} , stopping follow_users".format(err))
            self.logFile.write("Warning: {} , stopping follow_users\n".format(err))

            return self
        else:
            print("Sorry, an error occured: {}".format(err))
            self.logFile.write("Sorry, an error occured: {}\n".format(err))
            self.aborting = True

            return self

    print("--> Users: {} \n".format(len(userToInteract)))
    userToInteract = sample(
        userToInteract,
        int(ceil(self.user_interact_percentage * len(userToInteract) / 100)),
    )

    self.like_by_users(
        userToInteract,
        self.user_interact_amount,
        self.user_interact_random,
        self.user_interact_media,
    )

    return self