Skip to content

Commit 47880d1

Browse files
committed
fixed version incompability
1 parent 02284b3 commit 47880d1

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

test.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import platform
12
import random
3+
import subprocess
4+
import sys
25
import time
36

47
import undetected_chromedriver as uc
@@ -8,10 +11,41 @@
811
from selenium.webdriver.support import expected_conditions as EC
912
from selenium.webdriver.support.ui import WebDriverWait
1013

11-
uc.install()
12-
14+
print('This will open one chrome driver to test if everything works as expected.\n')
15+
16+
print('Getting Chrome Driver...')
17+
18+
OSNAME = platform.system()
19+
20+
"""
21+
Getting Chrome version code has been taken from
22+
https://github.com/yeongbin-jo/python-chromedriver-autoinstaller
23+
Thanks goes to him.
24+
"""
25+
if OSNAME == 'Linux':
26+
with subprocess.Popen(['chromium-browser', '--version'], stdout=subprocess.PIPE) as proc:
27+
version = proc.stdout.read().decode('utf-8').replace('Chromium', '').strip()
28+
version = version.replace('Google Chrome', '').strip()
29+
elif OSNAME == 'Darwin':
30+
process = subprocess.Popen(
31+
['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', '--version'], stdout=subprocess.PIPE)
32+
version = process.communicate()[0].decode(
33+
'UTF-8').replace('Google Chrome', '').strip()
34+
elif OSNAME == 'Windows':
35+
process = subprocess.Popen(
36+
['reg', 'query', 'HKEY_CURRENT_USER\\Software\\Google\\Chrome\\BLBeacon', '/v', 'version'],
37+
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL
38+
)
39+
version = process.communicate()[0].decode('UTF-8').strip().split()[-1]
40+
else:
41+
print('{} OS is not supported.'.format(OSNAME))
42+
sys.exit()
43+
44+
major_version = version.split('.')[0]
45+
46+
uc.TARGET_VERSION = major_version
1347

14-
print('This will open one chrome driver to test if everything works as expected.')
48+
uc.install()
1549

1650
driver = None
1751

0 commit comments

Comments
 (0)