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

假装没事ソ 提交于 2019-12-24 12:19:56

问题


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

回答1:


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:

  • You are using chromedriver=2.43
  • Release Notes of chromedriver=2.43 clearly mentions the following :

Supports Chrome v69-71

  • You are using chrome=73.0
  • Release Notes of ChromeDriver v2.46 clearly mentions the following :

Supports Chrome v71-73

So there is a clear mismatch between ChromeDriver v2.43 and the Chrome Browser v73.0


Solution

  • Upgrade ChromeDriver to current ChromeDriver v2.46 level.
  • Keep Chrome version at Chrome v73 level. (as per ChromeDriver v2.46 release notes)
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Execute your @Test.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

Update

Currently GAed Chrome v73 have some issues and you may like to downgrade to Chrome v72. You can find a couple of relevant discussions in:

  • Getting Timed out receiving message from renderer: 600.000 When we execute selenium scripts using Jenkins windows service mode
  • Timed out receiving message from renderer: 10.000 while capturing screenshot using chromedriver and chrome through Jenkins on Windows


来源:https://stackoverflow.com/questions/55397792/typeerror-nonetype-object-is-not-subscriptable-while-invoking-execute-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!