4

I try to upload an image/file on Facebook Messager, whose sample URL is https://www.facebook.com/messages/t/471646182511990 (If you want to try, you need to open Facebook Messager on your Chrome browser and get a valid URL). But it failed with an "Unknow command" exception.

I search but cannot find any suitable answer. A thread "https://stackoverflow.com/questions/63272928/selenium-webdriver-python-cant-upload-file-send-keys-is-throws-elementnotinte" is close but it is NOT the same problem.

Version:

  1. Python 3.9
  2. selenium: 4.1.0

Code:

def sendMedia(mediaFile):
    filePath="file.jpg")
    try:
        fileInputBox = driver.find_element_by_xpath("//input[@type='file']")
    except
        return False
    fileInputBox.send_keys(filePath)
    sleep(randint(1,2))
    fileInputBox.send_keys(Keys.ENTER)
    sleep(randint(5, 6))
    return True

Problem: This line "fileInputBox.send_keys(filePath)" return the below error:

Traceback (most recent call last): File "D:\Workspace\Property\Facebook\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 785, in _upload raise e

File "D:\Workspace\Property\Facebook\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 776, in _upload return self._execute(Command.UPLOAD_FILE, {'file': content})['value']

File "D:\Workspace\Property\Facebook\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 710, in _execute return self._parent.execute(command, params)

File "D:\Workspace\Property\Facebook\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in execute self.error_handler.check_response(response)

File "D:\Workspace\Property\Facebook\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.WebDriverException: Message: unknown command: unknown command: session/83896857b2899e4a7c53c4a8dca78976/se/file

Stacktrace:

Backtrace:

Ordinal0 [0x00C16903+2517251]

Ordinal0 [0x00BAF8E1+2095329]

Ordinal0 [0x00AB2848+1058888]

Ordinal0 [0x00AF429E+1327774]

Ordinal0 [0x00AF4089+1327241]

Ordinal0 [0x00A950AF+938159]

Ordinal0 [0x00A955C6+939462]

Ordinal0 [0x00A958F1+940273]

GetHandleVerifier [0x00DA5904+1577972]

GetHandleVerifier [0x00E50B97+2279047]

GetHandleVerifier [0x00CA6D09+534521]

GetHandleVerifier [0x00CA5DB9+530601]

Ordinal0 [0x00BB4FF9+2117625]

Ordinal0 [0x00A94E40+937536]

Ordinal0 [0x00A94848+936008]

GetHandleVerifier [0x00E78B5C+2442828]

BaseThreadInitThunk [0x7732FA29+25]

RtlGetAppContainerNamedObjectPath [0x775C7A9E+286]

RtlGetAppContainerNamedObjectPath [0x775C7A6E+238]

2 Answers 2

1

I have the same issue with Selenium 4.1.0 and Python 3.9. I have made some workaround but I don't like it.

In selenium site-package in remote_connection.py file I have changed line 218 from: Command.UPLOAD_FILE: ('POST', "/session/$sessionId/se/file"), to: Command.UPLOAD_FILE: ('POST', "/session/$sessionId/file"),

Now it is working but as I said it shouldn't be like that I guess.

Sign up to request clarification or add additional context in comments.

Comments

0

Mark's Answer is working for me.

In order to keep package code clean, I use a workaround as below:

from selenium.webdriver import Remote
from selenium.webdriver.remote import remote_connection
from selenium.webdriver.remote.command import Command

def do_something(url: str, session_id: str)

    rmt_con = remote_connection.RemoteConnection(url)
    rmt_con._commands.update({
        Command.UPLOAD_FILE: ("POST", "/session/$sessionId/file")
    })
    driver = Remote(command_executor=rmt_con, desired_capabilities={})
    driver.session_id = session_id
    
    # Do amazing things afterwards
    driver.get('')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.