M
M
Maxim Turchenko2019-01-21 13:57:28
Python
Maxim Turchenko, 2019-01-21 13:57:28

How to fix the error File "..webdriver.py", line 81, in. __init__ desired_capabilities=desired_capabilities)?

I'm trying to run a simple script with selenium:

#!/usr/bin/python
# This Python file uses the following encoding: utf-8

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
 
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.add_argument("--no-sandbox")
options.add_argument("--disable-setuid-sandbox") 
driver = webdriver.Chrome("/var/chromedriver/chromedriver") 
driver.get('https://google.com')
print(driver.title)
driver.quit()

5c45a523d97d8115432908.jpeg
Everything is fine with the version, here it is:
5c45a578ec0d8487417931.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nick V, 2019-01-21
@surenice

Something like this
from functools import partial
from pathlib import Path
from platform import system

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

ROOT_DIR = Path(__file__).parents[0]

if __name__ == '__main__':
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.binary_location = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
    local_system = system()
    make_path = partial(Path.joinpath, ROOT_DIR, 'chrome_drivers')
    if local_system == 'Linux':
        driver_path = make_path('chromedriver_linux64')
    elif local_system == 'Darwin':
        driver_path = make_path('chromedriver_mac64')
    elif local_system == 'Windows':
        driver_path = make_path('chromedriver_win32.exe')
    else:
        raise RuntimeError('Unknown os system')

    driver = webdriver.Chrome(executable_path=str(driver_path), options=chrome_options)
    driver.get('https://www.google.com/')
    print(driver.title)
    driver.quit()

Plus everything that Pavel Denisov wrote to you in the comments.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question