TypeError: 'NoneType' object is not subscriptable while invoking execute_script() for Chrome Download Manager through Selenium

General Tech Bugs & Fixes 2 years ago

0 3 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (3)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I have been using this function https://stackoverflow.com/a/48267887/11220889 for waiting for downloads to finish and returning the file path once finished. And it has been working great until now.

The Function

def every_downloads_chrome(driver):
    if not driver.current_url.startswith("chrome://downloads"):
        driver.get("chrome://downloads/")
    return driver.execute_script('''
        var items = downloads.Manager.get().items_;
        if (items.every(e => e.state === "COMPLETE"))
            return items.map(e => e.file_url);
        ''')

How its called

paths = WebDriverWait(driver, 120, 1).until(every_downloads_chrome)

Error I'm receiving

TypeError: 'NoneType' object is not subscriptable

So from what I can gather something has changed that has started causing the function to not return a path. I believe this is due to a change within chrome or even more specifically the chrome driver. My two reasons for this assumption is:

1) I had this function in another code that my colleague was using and she called me saying it was producing this error yesterday.

2)Neither code has changed so the change must be in chrome

I would like to keep using this script but if not possible have another function that waits for the downloads to finish and returns the paths and ideally does it all through the driver not through file path since multiple users use my codes on multiple machines.

EDIT: Versions-

Name: selenium
Version: 3.141.0

Name: Chrome Browser
Version: 73.0.3683.86

Name: Chrome Driver
Version: 2.43.600210

Name: System
Version: Windows 10 Pro x64
profilepic.png
manpreet 2 years ago
The error is self-explanatory. You are trying to subscript an object which you think is a list or dict, but actually is None. This means that you tried to do: None[something] This error means that you attempted to index an object that doesn't have that functionality. You might have noticed that the method sort() that only modify the list have no return value printed – they return the default None. 'NoneType' object is not subscriptable is the one thrown by python when you use the square bracket notation object[key] where an object doesn't define the __getitem__ method . This is a design principle for all mutable data structures in Python. http://net-informations.com/python/err/nonetype.htm
0 views   0 shares

profilepic.png
manpreet 2 years ago

As per the error message:

TypeError: 'NoneType' object is not subscriptable

Your main issue seems to be incompatibility between the version of the binaries you are using as follows:


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.