Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么图像上载失败,错误为selenium.common.exceptions.WebDriverException:消息:未知错误:无法聚焦元素_Python_Selenium_Selenium Webdriver_Webdriver_Selenium Chromedriver - Fatal编程技术网

Python 为什么图像上载失败,错误为selenium.common.exceptions.WebDriverException:消息:未知错误:无法聚焦元素

Python 为什么图像上载失败,错误为selenium.common.exceptions.WebDriverException:消息:未知错误:无法聚焦元素,python,selenium,selenium-webdriver,webdriver,selenium-chromedriver,Python,Selenium,Selenium Webdriver,Webdriver,Selenium Chromedriver,此错误消息 File "C:\Users\Dell\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute self.error_handler.check_response(response) File "C:\Users\Dell\AppData\Local\Programs\Python\

此错误消息

  File "C:\Users\Dell\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element
  (Session info: chrome=66.0.3359.181)
  (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.16299 x86_64)
…意味着WebDriver实例,即驱动程序无法关注通过定位器策略识别的元素

您的主要问题是,您正试图使用以下定位器策略在元素上调用
send_keys()

此定位器策略识别一个列表元素,如下所示:

driver.find_element_by_xpath('//*[@id="computer"]')
  • 标记不接受任何字符序列。只有
    标记接受字符序列。因此,当您尝试调用
    send_keys()
    时,驱动程序无法在元素上设置焦点

    因此图像上传失败

    元素快照:


    那么,我该如何上传图像呢?@PrashantSanap也许要上传图像,你必须探索其他选项,例如AutoIT或RIDEframework@DebanjanB谢谢
    selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element
    
    driver.find_element_by_xpath('//*[@id="computer"]')
    
    <li id="computer" style="width:160px !important;" class="computer firstUpload" data-api="" data-value="upload" title="Computer"></li>