Python代码返回“无法从'selenium.webdriver.common.keys'导入名称'keys'”

时间:2019-07-25 17:45:31

标签: python voice-recognition pyaudio watson-assistant

我有此代码,但无法正常工作。我该如何解决?

from selenium import webdriver  # to control browser operations
from selenium.webdriver.common.keys import keys
from io import Bytesio
from io import Stringio


runfile('/Users/saksham/saksham py/voice.py', wdir='/Users/saksham/saksham py')
Traceback (most recent call last):

  File "<ipython-input-1-f68c9e511ab8>", line 1, in <module>
    runfile('/Users/saksham/saksham py/voice.py', wdir='/Users/saksham/saksham py')

  File "/Users/saksham/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "/Users/saksham/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/Users/saksham/saksham py/voice.py", line 9, in <module>
    from selenium.webdriver.common.keys import keys

ImportError: cannot import name 'keys' from 'selenium.webdriver.common.keys' (/Users/saksham/anaconda3/lib/python3.7/site-packages/selenium/webdriver/common/keys.py)

1 个答案:

答案 0 :(得分:2)

替换

from selenium.webdriver.common.keys import keys

使用

from selenium.webdriver.common.keys import Keys

Based on the documentation