# Buggy code
def follow_user(browser, follow_restrict, login, user_name):
    """Follows the user of the currently opened image"""

    try:
        follow_button = browser.find_element_by_xpath("//*[contains(text(), 'Follow')]")
        sleep(2)  # Do we still need this sleep?
        follow_button.send_keys("\n")

        print("--> Now following")
        log_followed_pool(login, user_name)
        follow_restrict[user_name] = follow_restrict.get(user_name, 0) + 1
        sleep(3)
        return 1
    except NoSuchElementException:
        print("--> Already following")
        sleep(1)
        return 0


# Traceback (selenium.common.exceptions.ElementNotVisibleException)
[7/33]
Image from: b'bruhmusicals'
Number of Followers: 399157
Link: b'https://www.instagram.com/p/BYdcFanFczK/?tagged=followme'
Description: b'Comment "prank" letter by letter\xf0\x9f\x98\x82 // Follow @bruhmusicals if you\'re viewing\xf0\x9f\x94\xa5'
--> Image Liked!
--> Commented: b'Super!'
Traceback (most recent call last):
File "quickstart.py", line 15, in <module>
.set_comments(['Super!','Nice!','Cool'])\
File "/home/tm/Desktop/Projets Info/Instagram/InstaPy/instapy/instapy.py", line 531, in like_by_tags
followed += follow_user(self.browser, self.follow_restrict, self.username, user_name)
File "/home/tm/Desktop/Projets Info/Instagram/InstaPy/instapy/unfollow_util.py", line 134, in follow_user
follow_button.send_keys("\n")
File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 350, in send_keys
'value': keys_to_typing(value)})
File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 499, in _execute
return self._parent.execute(command, params)
File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 297, in execute
self.error_handler.check_response(response)
File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
(Session info: chrome=60.0.3112.101)
(Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 4.12.8-2-ARCH x86_64)

# Fixed code
def follow_user(browser, follow_restrict, login, user_name):
    """Follows the user of the currently opened image"""

    try:
        follow_button = browser.find_element_by_xpath("//*[contains(text(), 'Follow')]")

        sleep(2)  # Do we still need this sleep?
        if follow_button.is_displayed():
            follow_button.send_keys("\n")
        else:
            driver.execute_script(
                "arguments[0].style.visibility = 'visible'; arguments[0].style.height = '10px'; arguments[0].style.width = '10px'; arguments[0].style.opacity = 1",
                follow_button,
            )
            follow_button.click()

        print("--> Now following")
        log_followed_pool(login, user_name)
        follow_restrict[user_name] = follow_restrict.get(user_name, 0) + 1
        sleep(3)
        return 1
    except NoSuchElementException:
        print("--> Already following")
        sleep(1)
        return 0