1

For some reason my Python code displays as unreachable after adding a series of WebDriver options. Does anyone know why this is happening and how it can be fixed? enter image description here

Code itself is below:

class DriverOptions(object):

  def __init__(self):

    self.options = Options()
    self.options.add_argument('--no-sandbox')
    self.options.add_argument('--start-maximized')
    self.options.add_argument('--start-fullscreen')
    self.options.add_argument('--single-process')
    self.options.add_argument('--disable-dev-shm-usage')
    self.options.add_argument("--incognito")
    self.options.add_argument('--disable-blink-features=AutomationControlled')
    self.options.add_argument('--disable-blink-features=AutomationControlled')
    self.options.add_experimental_option('useAutomationExtension', False)
    self.options.add_experimental_option("excludeSwitches", ["enable-automation"])
    self.options.add_argument("disable-infobars")

    self.helperSpoofer = Spoofer()

    self.options.add_argument('user-agent={}'.format(self.helperSpoofer.userAgent))
    self.options.add_argument('--proxy-server=%s' % self.helperSpoofer.ip)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
frumsky
  • 39
  • 6

3 Answers3

5

There is a bug in Selenium 4.0. Just try updating your pip and simply uninstalling the selenium and reinstalling it. It solved a problem for me.

pip install selenium --upgrade
Jay Thorat
  • 70
  • 1
  • 4
  • 1
    This worked for me, I was getting the same error whenever using `Webdriver.Chrome` – Amon Oct 21 '22 at 03:25
  • 1
    Worked for me, updating from `3.141.0` to `4.7.2`. Let me add this bug is a wasted-all-afternoon level bug. – P. Navarro Dec 30 '22 at 16:28
0

Possibly you are using too many arguments and you can remove some of the arguments which are no more relevant:

  • Remove the --no-sandbox argument and execute as non-root user.
  • Either use --start-maximized or --start-fullscreen, avoid using both.
  • If you aren't using --no-sandbox you can also remove --disable-dev-shm-usage'
  • Remove the --incognito argument as it is no more effective.
  • Remove the --disable-infobars argument as it is no more effective.
  • Add the argument '--disable-blink-features=AutomationControlled' only once.
  • The argument --single-process looks to me an overkill as it runs the renderer and plugins in the same process as the browser and you may like to drop it.

A simpler yet effective code block can be:

class DriverOptions(object):
    def __init__(self):
        self.options = Options()
        self.options.add_argument('--start-maximized')
        self.options.add_argument('--disable-blink-features=AutomationControlled')
        self.options.add_experimental_option('useAutomationExtension', False)
        self.options.add_experimental_option("excludeSwitches", ["enable-automation"])
        self.options.add_argument("disable-infobars")
        self.helperSpoofer = Spoofer()
        self.options.add_argument('user-agent={}'.format(self.helperSpoofer.userAgent))
        self.options.add_argument('--proxy-server=%s' % self.helperSpoofer.ip)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

This bug is in selenium v4.1.3-4.1.4.

Update the Selenium library.

NETkuz
  • 1