prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Cannot focus element error
  I'm running the script on mac and after some time i get this error:
  
  Message: unknown error: cannot focus element
    (Session info: chrome=61.0.3163.100)
    (Driver info: chromedriver=2.32.498537 (cb2f855cbc7b82e20387eaf9a43f6b99b6105061),platform=Mac OS X 10.12.3 x86_64)
  
  Now I'm trying to update chromedriver with all of the packages to check whether they are the reason, but does anybody else get this error?
  
  </issue>
  <code>
  [start of instapy/comment_util.py]
  1 # -*- coding: utf-8 -*-
  2 """Module which handles the commenting features"""
  3 from random import choice
  4 from .time_util import sleep
  5 import emoji
  6 
  7 
  8 def comment_image(browser, comments):
  9     """Checks if it should comment on the image"""
  10     rand_comment = (choice(comments))
  11     rand_comment = emoji.demojize(rand_comment)
  12     rand_comment = emoji.emojize(rand_comment, use_aliases=True)
  13 
  14     comment_input = browser.find_elements_by_xpath(
  15         '//textarea[@placeholder = "Add a comment…"]')
  16     if len(comment_input) <= 0:
  17         comment_input = browser.find_elements_by_xpath(
  18             '//input[@placeholder = "Add a comment…"]')
  19 
  20     if len(comment_input) > 0:
  21         browser.execute_script(
  22             "arguments[0].value = '" + rand_comment + " ';", comment_input[0])
  23         # An extra space is added here and then deleted.
  24         # This forces the input box to update the reactJS core
  25         comment_input[0].send_keys("\b")
  26         comment_input[0].submit()
  27     else:
  28         print('--> Warning: Comment Action Likely Failed:'
  29               ' Comment Element not found')
  30 
  31     print("--> Commented: {}".format(rand_comment.encode('utf-8')))
  32     sleep(2)
  33 
  34     return 1
  35
  [end of instapy/comment_util.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/instapy/comment_util.py b/instapy/comment_util.py
  --- a/instapy/comment_util.py
  +++ b/instapy/comment_util.py
  @@ -2,8 +2,31 @@
   """Module which handles the commenting features"""
   from random import choice
   from .time_util import sleep
  +from selenium.common.exceptions import WebDriverException
   import emoji
   
  +def get_comment_input(browser):
  +    comment_input = browser.find_elements_by_xpath(
  +        '//textarea[@placeholder = "Add a comment…"]')
  +    if len(comment_input) <= 0:
  +        comment_input = browser.find_elements_by_xpath(
  +            '//input[@placeholder = "Add a comment…"]')
  +    return comment_input
  +
  +def open_comment_section(browser):
  +    missing_comment_elem_warning = (
  +        '--> Warning: Comment Button Not Found:'
  +        ' May cause issues with browser windows of smaller widths')
  +    comment_elem = browser.find_elements_by_xpath(
  +        "//a[@role='button']/span[text()='Comment']/..")
  +    if len(comment_elem) > 0:
  +        try:
  +            browser.execute_script(
  +                "arguments[0].click();", comment_elem[0])
  +        except WebDriverException:
  +            print(missing_comment_elem_warning)
  +    else:
  +        print(missing_comment_elem_warning)
   
   def comment_image(browser, comments):
       """Checks if it should comment on the image"""
  @@ -11,18 +34,19 @@
       rand_comment = emoji.demojize(rand_comment)
       rand_comment = emoji.emojize(rand_comment, use_aliases=True)
   
  -    comment_input = browser.find_elements_by_xpath(
  -        '//textarea[@placeholder = "Add a comment…"]')
  -    if len(comment_input) <= 0:
  -        comment_input = browser.find_elements_by_xpath(
  -            '//input[@placeholder = "Add a comment…"]')
  +    open_comment_section(browser)
  +    comment_input = get_comment_input(browser)
   
       if len(comment_input) > 0:
  +        comment_input[0].clear()
  +        comment_input = get_comment_input(browser)
  +
           browser.execute_script(
               "arguments[0].value = '" + rand_comment + " ';", comment_input[0])
           # An extra space is added here and then deleted.
           # This forces the input box to update the reactJS core
           comment_input[0].send_keys("\b")
  +        comment_input = get_comment_input(browser)
           comment_input[0].submit()
       else:
           print('--> Warning: Comment Action Likely Failed:'
  
verification_info: {"golden_diff": "diff --git a/instapy/comment_util.py b/instapy/comment_util.py\n--- a/instapy/comment_util.py\n+++ b/instapy/comment_util.py\n@@ -2,8 +2,31 @@\n \"\"\"Module which handles the commenting features\"\"\"\n from random import choice\n from .time_util import sleep\n+from selenium.common.exceptions import WebDriverException\n import emoji\n \n+def get_comment_input(browser):\n+    comment_input = browser.find_elements_by_xpath(\n+        '//textarea[@placeholder = \"Add a comment\u2026\"]')\n+    if len(comment_input) <= 0:\n+        comment_input = browser.find_elements_by_xpath(\n+            '//input[@placeholder = \"Add a comment\u2026\"]')\n+    return comment_input\n+\n+def open_comment_section(browser):\n+    missing_comment_elem_warning = (\n+        '--> Warning: Comment Button Not Found:'\n+        ' May cause issues with browser windows of smaller widths')\n+    comment_elem = browser.find_elements_by_xpath(\n+        \"//a[@role='button']/span[text()='Comment']/..\")\n+    if len(comment_elem) > 0:\n+        try:\n+            browser.execute_script(\n+                \"arguments[0].click();\", comment_elem[0])\n+        except WebDriverException:\n+            print(missing_comment_elem_warning)\n+    else:\n+        print(missing_comment_elem_warning)\n \n def comment_image(browser, comments):\n     \"\"\"Checks if it should comment on the image\"\"\"\n@@ -11,18 +34,19 @@\n     rand_comment = emoji.demojize(rand_comment)\n     rand_comment = emoji.emojize(rand_comment, use_aliases=True)\n \n-    comment_input = browser.find_elements_by_xpath(\n-        '//textarea[@placeholder = \"Add a comment\u2026\"]')\n-    if len(comment_input) <= 0:\n-        comment_input = browser.find_elements_by_xpath(\n-            '//input[@placeholder = \"Add a comment\u2026\"]')\n+    open_comment_section(browser)\n+    comment_input = get_comment_input(browser)\n \n     if len(comment_input) > 0:\n+        comment_input[0].clear()\n+        comment_input = get_comment_input(browser)\n+\n         browser.execute_script(\n             \"arguments[0].value = '\" + rand_comment + \" ';\", comment_input[0])\n         # An extra space is added here and then deleted.\n         # This forces the input box to update the reactJS core\n         comment_input[0].send_keys(\"\\b\")\n+        comment_input = get_comment_input(browser)\n         comment_input[0].submit()\n     else:\n         print('--> Warning: Comment Action Likely Failed:'\n", "issue": "Cannot focus element error\nI'm running the script on mac and after some time i get this error:\r\n\r\nMessage: unknown error: cannot focus element\r\n  (Session info: chrome=61.0.3163.100)\r\n  (Driver info: chromedriver=2.32.498537 (cb2f855cbc7b82e20387eaf9a43f6b99b6105061),platform=Mac OS X 10.12.3 x86_64)\r\n\r\nNow I'm trying to update chromedriver with all of the packages to check whether they are the reason, but does anybody else get this error?\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Module which handles the commenting features\"\"\"\nfrom random import choice\nfrom .time_util import sleep\nimport emoji\n\n\ndef comment_image(browser, comments):\n    \"\"\"Checks if it should comment on the image\"\"\"\n    rand_comment = (choice(comments))\n    rand_comment = emoji.demojize(rand_comment)\n    rand_comment = emoji.emojize(rand_comment, use_aliases=True)\n\n    comment_input = browser.find_elements_by_xpath(\n        '//textarea[@placeholder = \"Add a comment\u2026\"]')\n    if len(comment_input) <= 0:\n        comment_input = browser.find_elements_by_xpath(\n            '//input[@placeholder = \"Add a comment\u2026\"]')\n\n    if len(comment_input) > 0:\n        browser.execute_script(\n            \"arguments[0].value = '\" + rand_comment + \" ';\", comment_input[0])\n        # An extra space is added here and then deleted.\n        # This forces the input box to update the reactJS core\n        comment_input[0].send_keys(\"\\b\")\n        comment_input[0].submit()\n    else:\n        print('--> Warning: Comment Action Likely Failed:'\n              ' Comment Element not found')\n\n    print(\"--> Commented: {}\".format(rand_comment.encode('utf-8')))\n    sleep(2)\n\n    return 1\n", "path": "instapy/comment_util.py"}]}