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:
- Python 3.9
- 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]