0

I have this specific error :

desired_capabilities = options.to_capabilities() TypeError:
   to_capabilities() missing 1 required positional argument: 'self'.

I don't understand what is wrong because Options has parenthesis.

import sys
from selenium import webdriver
from bs4 import BeautifulSoup
import csv
import urllib.parse
from datetime import datetime
from datetime import date

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.chrome.options import Options



width = 400
height = 768
chrome_options = Options()
chrome_options.page_load_strategy = 'normal'
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('useAutomationExtension', False)
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--lang=en')
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--allow-running-insecure-content')
chrome_options.add_argument('--disable-notifications')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-browser-side-navigation')
chrome_options.add_argument('--mute-audio')
chrome_options.headless = True
chrome_options.add_argument('--force-device-scale-factor=1')
chrome_options.add_argument(f'window-size={width}x{height}')

driver = webdriver.Chrome(options=Options)
driver.set_page_load_timeout(7)
大陸北方網友
  • 3,696
  • 3
  • 12
  • 37
Mathieu
  • 797
  • 2
  • 6
  • 24

1 Answers1

0

You have initialized an instance of Options() Class by the name chrome_options.

So you have to pass chrome_options as an argument while spinning up the ChromeDriver and . So you have to change the line as:

webdriver.Chrome(options=chrome_options)

Effectively, your line of code will be:

driver = webdriver.Chrome(options=chrome_options)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Sometimes the answer is in front of us.... Sorry, I have to wait 8 min to validate your asnwer. Thank you for your help :) – Mathieu Feb 04 '21 at 07:16