We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `instapy/comment_util.py`
Content:
```
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 FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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:'

{"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"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Module which handles the commenting features\"\"\"\nfrom random import choice\nfrom .time_util import sleep\nfrom selenium.common.exceptions import WebDriverException\nimport emoji\n\ndef 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\ndef 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\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    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              ' 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"}]}