Repository: InstaPy/InstaPy

Issue:
Do not working on Windows 10
## Expected Behavior
Start working 
## Current Behavior
Give an error message
## Possible Solution (optional)

Cookie file not found, creating cookie...

Error: INFO [2018-03-19 16:29:02] [williansalceda] Session started - 2018-03-19 16:29:02
 WARNING [2018-03-19 16:29:02] [williansalceda] Sorry, Record Activity is not working on Windows. We're working to fix this soon!
 Traceback (most recent call last):
 File "quickstart.py", line 5, in <module>
 session.login()
 File "C:\Users\BoneS\Desktop\InstaPy-master\instapy\instapy.py", line 264, in login
 self.bypass_suspicious_attempt):
 File "C:\Users\BoneS\Desktop\InstaPy-master\instapy\login_util.py", line 133, in login_user
 "//select[@class='_fsoey']/option[text()='English']").click()
 File "C:\Users\BoneS\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
 self._execute(Command.CLICK_ELEMENT)
 File "C:\Users\BoneS\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
 return self._parent.execute(command, params)
 File "C:\Users\BoneS\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
 self.error_handler.check_response(response)
 File "C:\Users\BoneS\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
 raise exception_class(message, screen, stacktrace)
 selenium.common.exceptions.WebDriverException: Message: unknown error: call function result missing 'value'
 (Session info: chrome=65.0.3325.162)
 (Driver info: chromedriver=2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform=Windows NT 10.0.16299 x86_64)
 


Discussion:

Resolving patch:
diff --git a/instapy/instapy.py b/instapy/instapy.py
--- a/instapy/instapy.py
+++ b/instapy/instapy.py
@@ -2,6 +2,7 @@
 import csv
 import json
 import logging
+import re
 from math import ceil
 import os
 from platform import python_version
@@ -9,6 +10,7 @@
 from sys import maxsize
 import random
 
+import selenium
 from pyvirtualdisplay import Display
 from selenium import webdriver
 from selenium.common.exceptions import NoSuchElementException, WebDriverException
@@ -247,9 +249,22 @@ def set_selenium_local_session(self):
                 'intl.accept_languages': 'en-US'
             }
             chrome_options.add_experimental_option('prefs', chrome_prefs)
-            self.browser = webdriver.Chrome(chromedriver_location,
-                                            desired_capabilities=capabilities,
-                                            chrome_options=chrome_options)
+            try:
+                self.browser = webdriver.Chrome(chromedriver_location,
+                                                desired_capabilities=capabilities,
+                                                chrome_options=chrome_options)
+            except selenium.common.exceptions.WebDriverException as exc:
+                self.logger.exception(exc)
+                raise InstaPyError('ensure chromedriver is installed at {}'.format(
+                    Settings.chromedriver_location))
+
+            # prevent: Message: unknown error: call function result missing 'value'
+            matches = re.match(r'^(\d+\.\d+)',
+                               self.browser.capabilities['chrome']['chromedriverVersion'])
+            if float(matches.groups()[0]) < Settings.chromedriver_min_version:
+                raise InstaPyError('chromedriver {} is not supported, expects {}+'.format(
+                    float(matches.groups()[0]), Settings.chromedriver_min_version))
+
         self.browser.implicitly_wait(self.page_delay)
         self.logger.info('Session started - %s'
                          % (datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
diff --git a/instapy/settings.py b/instapy/settings.py
--- a/instapy/settings.py
+++ b/instapy/settings.py
@@ -8,3 +8,4 @@ class Settings:
     log_location = os.path.join(BASE_DIR, 'logs')
     database_location = os.path.join(BASE_DIR, 'db', 'instapy.db')
     chromedriver_location = os.path.join(BASE_DIR, 'assets', 'chromedriver')
+    chromedriver_min_version = 2.36


Test patch:
diff --git a/tests/test_instapy.py b/tests/test_instapy.py
--- a/tests/test_instapy.py
+++ b/tests/test_instapy.py
@@ -1,6 +1,7 @@
 from unittest.mock import patch, PropertyMock
 
 import pytest
+from selenium.common.exceptions import WebDriverException
 
 from instapy.instapy import InstaPy, InstaPyError
 
@@ -23,6 +24,31 @@ def test_like_by_users_with_no_usernames():
     assert isinstance(res, InstaPy)
 
 
+@patch('instapy.instapy.webdriver')
+def test_set_selenium_local_session_raises_missing_chromedriver(webdriver):
+    """Ensure chromedriver is installed"""
+    webdriver.Chrome.side_effect = WebDriverException()
+    with pytest.raises(InstaPyError):
+        InstaPy()
+
+
+@patch('instapy.instapy.webdriver')
+def test_set_selenium_local_session_raises_chromedriver_version(webdriver):
+    """Ensure chromedriver version is supported"""
+    webdriver.Chrome.return_value.capabilities = {'chrome': {
+        'chromedriverVersion': '2.35.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91)'}}
+    with pytest.raises(InstaPyError):
+        InstaPy()
+
+
+@patch('instapy.instapy.webdriver')
+def test_set_selenium_local_session_supports_chromedriver_version(webdriver):
+    """Ensure chromedriver version is supported"""
+    webdriver.Chrome.return_value.capabilities = {'chrome': {
+        'chromedriverVersion': '2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91)'}}
+    InstaPy()
+
+
 @patch('instapy.instapy.load_follow_restriction')
 def test_set_use_clarifai_raises_on_windows(load_follow_restriction):
     """windows not supported"""