简体   繁体   English

python中不受支持的操作数类型

[英]unsupported operand types in python

Following is the code I use for taking screenshots using Python (selenium) 以下是我用于使用Python(硒)拍摄屏幕截图的代码

path = os.mkdir('D:\screenshots' + time.strftime("%d%m"))
driver.get_screenshot_as_file(path + '\wishlist_' + str(i) + '.jpg')

However when i run this program, I am getting the following error, 但是,当我运行此程序时,出现以下错误,

Traceback (most recent call last): File "C:\\Users\\me\\Desktop\\domain.py", line 43, in test_bkpdomains 追溯(最近一次通话):文件“ C:\\ Users \\ me \\ Desktop \\ domain.py”,第43行,在test_bkpdomains中

driver.get_screenshot_as_file(path + '\wishlist_' + str(i) + '.jpg')

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' TypeError:+不支持的操作数类型:“ NoneType”和“ str”

Anyone pls help me to overcome this ? 任何人都可以帮助我克服这个困难吗?

You're trying to concatenate an empty object with a string in the second line. 您正在尝试将空对象与第二行中的字符串连接起来。

For example, 例如,

import os
path = os.mkdir('dummy')
print path

Returns None so you can't combine that with the strings in the second line. 返回None因此您无法将其与第二行中的字符串结合使用。 Perhaps if you make the directory and then just use the string for its path in the second line: 也许如果您创建目录,然后仅在第二行中使用字符串作为其路径:

path = '/path/to/directory' #string for usage below (can be concatenated)
os.mkdir(path) #make the actual directory 
driver.get_screenshot_as_file(path + '/wishlist_' + str(i) + '.jpg')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM