我现在要实现自动化上传文件,到上传文件那一步卡住了,页面显示如下

我的代码如下:

def test_11(self):
        time.sleep(1)
        self.browser.find_element_by_link_text(u'批量上传').click()
        time.sleep(1)
        self.browser.switch_to_frame('contentFrame')
        # 点击导入文档
        self.browser.find_element_by_id("filePicker").send_keys('C:\\E\\Users\\Administrator\\PycharmProjects\\WLTK\\jj.doc')
        time.sleep(2)

执行后报错如下:

Error
Traceback (most recent call last):
  File "C:\E\Users\Administrator\PycharmProjects\WLTK\Test\Test_WLTK\TestScripts.py", line 91, in test_11
    a.send_keys('C:\\E\\Users\\Administrator\\PycharmProjects\\WLTK\\jj.doc')
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 322, in send_keys
    self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': keys_to_typing(value)})
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 457, in _execute
    return self._parent.execute(command, params)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 233, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
WebDriverException: Message: unknown error: cannot focus element
  (Session info: chrome=51.0.2704.103)
  (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 10.0 x86_64)

请各位大神帮忙看看这个问题要怎么解决才可以实现上传?


↙↙↙阅读原文可查看相关链接,并与作者交流