Python - Selenium Chrome webdriver doesn't have components like WidevineCDM

1.9k views Asked by At

I'm trying to use Selenium to open a page and go to Netflix and open a video and play. Once I actually get to the video, I can't load it because I get the error:

Missing Components... Please visit chrome://components, locate the WidevineCdm component...

When going to chrome://components, there aren't any components installed. If I had opened Chrome regularly and navigated to the video like I did in Selenium, I can play it. When I got to chrome://components in regular Chrome, there are more components in there. I'm trying to find out how to import my normal Chrome settings but I can't seem to figure that out. I've tried using ChromeOptions and DesiredCapabilities.CHROME but I couldn't get it to work. I also can't find documentation on all the items inside the DesiredCapabilities.CHROME dictionary. I hope that once I'm able to get normal Chrome settings into the webdriver version, I'd be able to load Netflix videos via Selenium Chrome webdriver.

2

There are 2 answers

0
kakhkAtion On

This is not exactly the full solution, but I figured if you use the Chrome's default user directory AND exclude the disable-component-update switch, the component will be loaded properly. You can find the path for Chrome's default user directory for different platforms here*.

So for example on a Mac OS X, do this:

options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['disable-component-update'])
options.add_argument('--user-data-dir=~/Library/Application\ Support/Google/Chrome/')

driver = webdriver.Chrome(chrome_options=options)

driver.get('chrome://components/')

and you should see the WidevineCdm there!

I'll update this if I find a way to do it for custom user directories.

*Note that Default will be added to the end of the path automatically, so as you can see, I am NOT including Default at the end of user-data-dir passed to selenium.

UPDATE 1: Ok. I have a [hacky] solution if you want to use custom user dir. Excluding the --disable-component-update switch will load the components for you, but not completely. If you go to chrome://components you will see the components are there, but they all have version=0.0.0.0, and you need to click on the update button. Below is a simple loop that clicks on the update buttons:

options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['disable-component-update'])
options.add_argument('--user-data-dir=path/to/your/dir')

driver = webdriver.Chrome(chrome_options=options)

driver.get('chrome://components/')

components = driver.find_elements_by_class_name('button-check-update')
for c in components:
    try:
        c.click()
    except:
        pass

Note the try-except. You need it because there are some hidden buttons which throw an exception when you try to click them.

0
ab77 On

The following works, at least on OS X. Make sure to have the correct chromedriver executable in the working directory..

from selenium import webdriver

def buildDriver():
    options = webdriver.ChromeOptions()
    args = ['--user-data-dir=./ChromeProfile',
            '--disable-session-crashed-bubble',                
            '--disable-save-password-bubble',
            '--disable-permissions-bubbles',
            '--bwsi',
            '--incognito',
            '--disable-extensions']

    options.add_experimental_option('excludeSwitches', ['disable-component-update',
                                                        'ignore-certificate-errors'])
    for arg in args:
        options.add_argument(arg)

    chromedriver = './chromedriver'
    return webdriver.Chrome(chromedriver, chrome_options=options)


if __name__ == '__main__':
    driver = buildDriver()
    driver.get('chrome://components/')

I am not quite sure why this answer is being down-marked, because it precisely answers the question asked.