求助:上传图片失败,出现错误

Testing started at 14:14 ...
Launching pytest with arguments D:/软件测试/实战演练网址/pythonProject/selenium_file_alert/test_file.py in D:\软件测试\实战演练网址\pythonProject\selenium_file_alert

============================= test session starts =============================
platform win32 -- Python 3.9.1, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- C:\Users\liuna\AppData\Local\Programs\Python\Python39\python.exe
cachedir: .pytest_cache
rootdir: D:\软件测试\实战演练网址\pythonProject\selenium_file_alert
collecting ... collected 1 item

test_file.py::TestFile::test_file_upload FAILED                          [100%]
test_file.py:6 (TestFile.test_file_upload)
self = <selenium_file_alert.test_file.TestFile object at 0x000001C5E8FCF340>

    def test_file_upload(self):
        self.driver.get("https://image.baidu.com/")
>       self.driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[3]/div/div/div/div/div/div[2]/div/a/img[2]").click()

test_file.py:9: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\Users\liuna\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py:80: in click
    self._execute(Command.CLICK_ELEMENT)
C:\Users\liuna\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py:633: in _execute
    return self._parent.execute(command, params)
C:\Users\liuna\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py:321: in execute
    self.error_handler.check_response(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x000001C5E8FCFFA0>
response = {'status': 400, 'value': '{"value":{"error":"element not interactable","message":"Element <img class=\\"st_camera_on\\...CommandsChild.jsm:199:24\\nreceiveMessage@chrome://marionette/content/actors/MarionetteCommandsChild.jsm:100:31\\n"}}'}

    def check_response(self, response):
        """
        Checks that a JSON response from the WebDriver does not have an error.
    
        :Args:
         - response - The JSON response from the WebDriver server as a dictionary
           object.
    
        :Raises: If the response contains an error message.
        """
        status = response.get('status', None)
        if status is None or status == ErrorCode.SUCCESS:
            return
        value = None
        message = response.get("message", "")
        screen = response.get("screen", "")
        stacktrace = None
        if isinstance(status, int):
            value_json = response.get('value', None)
            if value_json and isinstance(value_json, basestring):
                import json
                try:
                    value = json.loads(value_json)
                    if len(value.keys()) == 1:
                        value = value['value']
                    status = value.get('error', None)
                    if status is None:
                        status = value["status"]
                        message = value["value"]
                        if not isinstance(message, basestring):
                            value = message
                            message = message.get('message')
                    else:
                        message = value.get('message', None)
                except ValueError:
                    pass
    
        exception_class = ErrorInResponseException
        if status in ErrorCode.NO_SUCH_ELEMENT:
            exception_class = NoSuchElementException
        elif status in ErrorCode.NO_SUCH_FRAME:
            exception_class = NoSuchFrameException
        elif status in ErrorCode.NO_SUCH_WINDOW:
            exception_class = NoSuchWindowException
        elif status in ErrorCode.STALE_ELEMENT_REFERENCE:
            exception_class = StaleElementReferenceException
        elif status in ErrorCode.ELEMENT_NOT_VISIBLE:
            exception_class = ElementNotVisibleException
        elif status in ErrorCode.INVALID_ELEMENT_STATE:
            exception_class = InvalidElementStateException
        elif status in ErrorCode.INVALID_SELECTOR \
                or status in ErrorCode.INVALID_XPATH_SELECTOR \
                or status in ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER:
            exception_class = InvalidSelectorException
        elif status in ErrorCode.ELEMENT_IS_NOT_SELECTABLE:
            exception_class = ElementNotSelectableException
        elif status in ErrorCode.ELEMENT_NOT_INTERACTABLE:
            exception_class = ElementNotInteractableException
        elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
            exception_class = InvalidCookieDomainException
        elif status in ErrorCode.UNABLE_TO_SET_COOKIE:
            exception_class = UnableToSetCookieException
        elif status in ErrorCode.TIMEOUT:
            exception_class = TimeoutException
        elif status in ErrorCode.SCRIPT_TIMEOUT:
            exception_class = TimeoutException
        elif status in ErrorCode.UNKNOWN_ERROR:
            exception_class = WebDriverException
        elif status in ErrorCode.UNEXPECTED_ALERT_OPEN:
            exception_class = UnexpectedAlertPresentException
        elif status in ErrorCode.NO_ALERT_OPEN:
            exception_class = NoAlertPresentException
        elif status in ErrorCode.IME_NOT_AVAILABLE:
            exception_class = ImeNotAvailableException
        elif status in ErrorCode.IME_ENGINE_ACTIVATION_FAILED:
            exception_class = ImeActivationFailedException
        elif status in ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
            exception_class = MoveTargetOutOfBoundsException
        elif status in ErrorCode.JAVASCRIPT_ERROR:
            exception_class = JavascriptException
        elif status in ErrorCode.SESSION_NOT_CREATED:
            exception_class = SessionNotCreatedException
        elif status in ErrorCode.INVALID_ARGUMENT:
            exception_class = InvalidArgumentException
        elif status in ErrorCode.NO_SUCH_COOKIE:
            exception_class = NoSuchCookieException
        elif status in ErrorCode.UNABLE_TO_CAPTURE_SCREEN:
            exception_class = ScreenshotException
        elif status in ErrorCode.ELEMENT_CLICK_INTERCEPTED:
            exception_class = ElementClickInterceptedException
        elif status in ErrorCode.INSECURE_CERTIFICATE:
            exception_class = InsecureCertificateException
        elif status in ErrorCode.INVALID_COORDINATES:
            exception_class = InvalidCoordinatesException
        elif status in ErrorCode.INVALID_SESSION_ID:
            exception_class = InvalidSessionIdException
        elif status in ErrorCode.UNKNOWN_METHOD:
            exception_class = UnknownMethodException
        else:
            exception_class = WebDriverException
        if value == '' or value is None:
            value = response['value']
        if isinstance(value, basestring):
            if exception_class == ErrorInResponseException:
                raise exception_class(response, value)
            raise exception_class(value)
        if message == "" and 'message' in value:
            message = value['message']
    
        screen = None
        if 'screen' in value:
            screen = value['screen']
    
        stacktrace = None
        if 'stackTrace' in value and value['stackTrace']:
            stacktrace = []
            try:
                for frame in value['stackTrace']:
                    line = self._value_or_default(frame, 'lineNumber', '')
                    file = self._value_or_default(frame, 'fileName', '<anonymous>')
                    if line:
                        file = "%s:%s" % (file, line)
                    meth = self._value_or_default(frame, 'methodName', '<anonymous>')
                    if 'className' in frame:
                        meth = "%s.%s" % (frame['className'], meth)
                    msg = "    at %s (%s)"
                    msg = msg % (meth, file)
                    stacktrace.append(msg)
            except TypeError:
                pass
        if exception_class == ErrorInResponseException:
            raise exception_class(response, message)
        elif exception_class == UnexpectedAlertPresentException:
            alert_text = None
            if 'data' in value:
                alert_text = value['data'].get('text')
            elif 'alert' in value:
                alert_text = value['alert'].get('text')
            raise exception_class(message, screen, stacktrace, alert_text)
>       raise exception_class(message, screen, stacktrace)
E       selenium.common.exceptions.ElementNotInteractableException: Message: Element <img class="st_camera_on" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAphJREFUaN7tWMtuEzEULeL1B7BgBYIljzhpK1iVJRtYVYjNeNJWgU3Z8AEE/iK/wA90DfsUCZb0HyhSCxW2dblnKiZ3otCxJ5MZovpKlkaJr32OfXz8WFmJESNGjKWPhwnd6GmbqNQMS0vi3qIucv4L8L2+faa0/dVJDIUUldifHW2ftgpeaeoyEBMKXpAw3T6pVsB3B3RZafMlB8PfXhLKZGS+yrzNIV1pnEBHm3eT0bRHq1t0yzcXdZEjZuN9o+DXtug+6/53DiB1u8EDwDlSSr1t6tQOdGNIl6BRpd2gKAH7TUjgExFdCG0bOZz7cdKOPSj0gT55jQFDtQWa0D2WyecyJ1lP6U5lE9im2wz8+MzFzhiApQJ4e1IC/kc3MY/ntuHUbKCts0nYE28SmLLCyGv7nUdpNLURvXj0iq7VJVW0hTbR9kRCdoS+5Ux4yQm6k+DXduhmKKD1Hbqu+vZ5V7s3KPjGb8FmwX1LEsDmQcANxMIaBcmBnYRz9rhTN0MGDv+tpvQgbLPkmchl616WJ/D05Qn87b2xafeatWw9dl+Lut4EQvFUIQBA0yDZIsfZ2skKf0+R8yWxcAKZbAQ4HA1mbUqn8hJHD87x2bwWTiDTvAD/ZJeu/qsu/iuen+xeqwTgLH8XrO+IFmaMc8vcaaEEYI9i9Mf+zmLGeR630RoBeHwVy5XWiDYigXMroaVfxEtvo/NuZD7noniUOBeHuZDjdOjlvVECdV9oWiNQ6+tfMIE5bmSLeb4UNzLGVr4Y+6QEgcOQF7e6A30DQ+5cPu+omx/ookrMviRReJVoqpxa8OHEvcw+sPlZYkp3y96FGi2MBZjCXp85Qc5EWwUYgsFLOc18G21EQm6Avr1lEyNGjBgxqsQfpdcIhlb9ZYwAAAAASUVORK5CYII="> could not be scrolled into view

C:\Users\liuna\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py:242: ElementNotInteractableException


Assertion failed


================================== FAILURES ===================================
__________________________ TestFile.test_file_upload __________________________

self = <selenium_file_alert.test_file.TestFile object at 0x000001C5E8FCF340>

    def test_file_upload(self):
        self.driver.get("https://image.baidu.com/")
>       self.driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[3]/div/div/div/div/div/div[2]/div/a/img[2]").click()

test_file.py:9: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\Users\liuna\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py:80: in click
    self._execute(Command.CLICK_ELEMENT)
C:\Users\liuna\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py:633: in _execute
    return self._parent.execute(command, params)
C:\Users\liuna\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py:321: in execute
    self.error_handler.check_response(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x000001C5E8FCFFA0>
response = {'status': 400, 'value': '{"value":{"error":"element not interactable","message":"Element <img class=\\"st_camera_on\\...CommandsChild.jsm:199:24\\nreceiveMessage@chrome://marionette/content/actors/MarionetteCommandsChild.jsm:100:31\\n"}}'}

    def check_response(self, response):
        """
        Checks that a JSON response from the WebDriver does not have an error.
    
        :Args:
         - response - The JSON response from the WebDriver server as a dictionary
           object.
    
        :Raises: If the response contains an error message.
        """
        status = response.get('status', None)
        if status is None or status == ErrorCode.SUCCESS:
            return
        value = None
        message = response.get("message", "")
        screen = response.get("screen", "")
        stacktrace = None
        if isinstance(status, int):
            value_json = response.get('value', None)
            if value_json and isinstance(value_json, basestring):
                import json
                try:
                    value = json.loads(value_json)
                    if len(value.keys()) == 1:
                        value = value['value']
                    status = value.get('error', None)
                    if status is None:
                        status = value["status"]
                        message = value["value"]
                        if not isinstance(message, basestring):
                            value = message
                            message = message.get('message')
                    else:
                        message = value.get('message', None)
                except ValueError:
                    pass
    
        exception_class = ErrorInResponseException
        if status in ErrorCode.NO_SUCH_ELEMENT:
            exception_class = NoSuchElementException
        elif status in ErrorCode.NO_SUCH_FRAME:
            exception_class = NoSuchFrameException
        elif status in ErrorCode.NO_SUCH_WINDOW:
            exception_class = NoSuchWindowException
        elif status in ErrorCode.STALE_ELEMENT_REFERENCE:
            exception_class = StaleElementReferenceException
        elif status in ErrorCode.ELEMENT_NOT_VISIBLE:
            exception_class = ElementNotVisibleException
        elif status in ErrorCode.INVALID_ELEMENT_STATE:
            exception_class = InvalidElementStateException
        elif status in ErrorCode.INVALID_SELECTOR \
                or status in ErrorCode.INVALID_XPATH_SELECTOR \
                or status in ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER:
            exception_class = InvalidSelectorException
        elif status in ErrorCode.ELEMENT_IS_NOT_SELECTABLE:
            exception_class = ElementNotSelectableException
        elif status in ErrorCode.ELEMENT_NOT_INTERACTABLE:
            exception_class = ElementNotInteractableException
        elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
            exception_class = InvalidCookieDomainException
        elif status in ErrorCode.UNABLE_TO_SET_COOKIE:
            exception_class = UnableToSetCookieException
        elif status in ErrorCode.TIMEOUT:
            exception_class = TimeoutException
        elif status in ErrorCode.SCRIPT_TIMEOUT:
            exception_class = TimeoutException
        elif status in ErrorCode.UNKNOWN_ERROR:
            exception_class = WebDriverException
        elif status in ErrorCode.UNEXPECTED_ALERT_OPEN:
            exception_class = UnexpectedAlertPresentException
        elif status in ErrorCode.NO_ALERT_OPEN:
            exception_class = NoAlertPresentException
        elif status in ErrorCode.IME_NOT_AVAILABLE:
            exception_class = ImeNotAvailableException
        elif status in ErrorCode.IME_ENGINE_ACTIVATION_FAILED:
            exception_class = ImeActivationFailedException
        elif status in ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
            exception_class = MoveTargetOutOfBoundsException
        elif status in ErrorCode.JAVASCRIPT_ERROR:
            exception_class = JavascriptException
        elif status in ErrorCode.SESSION_NOT_CREATED:
            exception_class = SessionNotCreatedException
        elif status in ErrorCode.INVALID_ARGUMENT:
            exception_class = InvalidArgumentException
        elif status in ErrorCode.NO_SUCH_COOKIE:
            exception_class = NoSuchCookieException
        elif status in ErrorCode.UNABLE_TO_CAPTURE_SCREEN:
            exception_class = ScreenshotException
        elif status in ErrorCode.ELEMENT_CLICK_INTERCEPTED:
            exception_class = ElementClickInterceptedException
        elif status in ErrorCode.INSECURE_CERTIFICATE:
            exception_class = InsecureCertificateException
        elif status in ErrorCode.INVALID_COORDINATES:
            exception_class = InvalidCoordinatesException
        elif status in ErrorCode.INVALID_SESSION_ID:
            exception_class = InvalidSessionIdException
        elif status in ErrorCode.UNKNOWN_METHOD:
            exception_class = UnknownMethodException
        else:
            exception_class = WebDriverException
        if value == '' or value is None:
            value = response['value']
        if isinstance(value, basestring):
            if exception_class == ErrorInResponseException:
                raise exception_class(response, value)
            raise exception_class(value)
        if message == "" and 'message' in value:
            message = value['message']
    
        screen = None
        if 'screen' in value:
            screen = value['screen']
    
        stacktrace = None
        if 'stackTrace' in value and value['stackTrace']:
            stacktrace = []
            try:
                for frame in value['stackTrace']:
                    line = self._value_or_default(frame, 'lineNumber', '')
                    file = self._value_or_default(frame, 'fileName', '<anonymous>')
                    if line:
                        file = "%s:%s" % (file, line)
                    meth = self._value_or_default(frame, 'methodName', '<anonymous>')
                    if 'className' in frame:
                        meth = "%s.%s" % (frame['className'], meth)
                    msg = "    at %s (%s)"
                    msg = msg % (meth, file)
                    stacktrace.append(msg)
            except TypeError:
                pass
        if exception_class == ErrorInResponseException:
            raise exception_class(response, message)
        elif exception_class == UnexpectedAlertPresentException:
            alert_text = None
            if 'data' in value:
                alert_text = value['data'].get('text')
            elif 'alert' in value:
                alert_text = value['alert'].get('text')
            raise exception_class(message, screen, stacktrace, alert_text)
>       raise exception_class(message, screen, stacktrace)
E       selenium.common.exceptions.ElementNotInteractableException: Message: Element <img class="st_camera_on" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAphJREFUaN7tWMtuEzEULeL1B7BgBYIljzhpK1iVJRtYVYjNeNJWgU3Z8AEE/iK/wA90DfsUCZb0HyhSCxW2dblnKiZ3otCxJ5MZovpKlkaJr32OfXz8WFmJESNGjKWPhwnd6GmbqNQMS0vi3qIucv4L8L2+faa0/dVJDIUUldifHW2ftgpeaeoyEBMKXpAw3T6pVsB3B3RZafMlB8PfXhLKZGS+yrzNIV1pnEBHm3eT0bRHq1t0yzcXdZEjZuN9o+DXtug+6/53DiB1u8EDwDlSSr1t6tQOdGNIl6BRpd2gKAH7TUjgExFdCG0bOZz7cdKOPSj0gT55jQFDtQWa0D2WyecyJ1lP6U5lE9im2wz8+MzFzhiApQJ4e1IC/kc3MY/ntuHUbKCts0nYE28SmLLCyGv7nUdpNLURvXj0iq7VJVW0hTbR9kRCdoS+5Ux4yQm6k+DXduhmKKD1Hbqu+vZ5V7s3KPjGb8FmwX1LEsDmQcANxMIaBcmBnYRz9rhTN0MGDv+tpvQgbLPkmchl616WJ/D05Qn87b2xafeatWw9dl+Lut4EQvFUIQBA0yDZIsfZ2skKf0+R8yWxcAKZbAQ4HA1mbUqn8hJHD87x2bwWTiDTvAD/ZJeu/qsu/iuen+xeqwTgLH8XrO+IFmaMc8vcaaEEYI9i9Mf+zmLGeR630RoBeHwVy5XWiDYigXMroaVfxEtvo/NuZD7noniUOBeHuZDjdOjlvVECdV9oWiNQ6+tfMIE5bmSLeb4UNzLGVr4Y+6QEgcOQF7e6A30DQ+5cPu+omx/ookrMviRReJVoqpxa8OHEvcw+sPlZYkp3y96FGi2MBZjCXp85Qc5EWwUYgsFLOc18G21EQm6Avr1lEyNGjBgxqsQfpdcIhlb9ZYwAAAAASUVORK5CYII="> could not be scrolled into view

C:\Users\liuna\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py:242: ElementNotInteractableException
============================== warnings summary ===============================
test_file.py:10
  D:\软件测试\实战演练网址\pythonProject\selenium_file_alert\test_file.py:10: DeprecationWarning: invalid escape sequence \p
    self.driver.find_element_by_id("stifle").send_keys("D:\软件测试\实战演练网址\pythonProject\img\微信图片_20210222104811.png")

<unknown>:10
  <unknown>:10: DeprecationWarning: invalid escape sequence \p

-- Docs: https://docs.pytest.org/en/stable/warnings.html
=========================== short test summary info ===========================
FAILED test_file.py::TestFile::test_file_upload - selenium.common.exceptions....
======================== 1 failed, 2 warnings in 7.94s ========================

Process finished with exit code 1


Assertion failed

Assertion failed

QQ截图20210222165456

你换成"D:/xxxx/xxxx"试试

  • 主要的报错是说你这个元素
    "/html/body/div[1]/div[1]/div[3]/div/div/div/div/div/div[2]/div/a/img[2]"
    不可交互
  • 建议确认一下这个元素定位是否准确,元素的状态是否正常
  • 可以考虑先在元素定位前加一个显式等待,确保定位的时候页面是加载完毕的
  • 如果还不行的话就要确认元素本身是否是不可交互的,点击效果是不是通过js的响应事件来实现的,可以换成鼠标操作试一下