TypeError:通过Selenium调用Chrome Download Manager的execute_script()时,"NoneType"对象无法下标 [英] TypeError: 'NoneType' object is not subscriptable while invoking execute_script() for Chrome Download Manager through Selenium

查看:177
本文介绍了TypeError:通过Selenium调用Chrome Download Manager的execute_script()时,"NoneType"对象无法下标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用此功能 https://stackoverflow.com/a/48267887/11220889 等待下载完成并在完成后返回文件路径.到目前为止,它一直运转良好.

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.

功能

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);
        ''')

它怎么称呼

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

我收到错误

TypeError: 'NoneType' object is not subscriptable

因此,从我可以收集到的信息来看,某些变化已经开始,导致该函数无法返回路径.我相信这是由于chrome或更确切地说是chrome驱动程序发生了变化.我做出此假设的两个原因是:

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)我在同事正在使用的另一个代码中具有此功能,她打电话给我,说昨天它产生了此错误.

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)两个代码都没有更改,因此更改必须是chrome

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.

版本-

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

推荐答案

根据错误消息:

TypeError: 'NoneType' object is not subscriptable

您的主要问题似乎是所使用的二进制版本之间的不兼容性:

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

支持 Chrome v69-71

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆