0

I want to upload file using the following python code:

driver.find_element_by_id("fileFieldName-file").send_keys("D:\\manual.pdf")

the code works fine in Firefox, but it fails in IE and Chrome. The exception is as follows:

WebDriverException: Message: '{ "status" : 404, "sessionId" : "<no session>", "value" : "Command not found: POST /session/e56793e2-79f9-4bb9-820e-91090ccee083/file" }'

1 Answer 1

0

I find the answer by myself. http://code.google.com/p/selenium/issues/detail?id=3736 It is a bug of selenium.The solution as follows: 1. find the file "webelement.py" in C:\Python27\Lib\site-packages\selenium-2.21.2-py2.7.egg\selenium\webdriver\remote 2. find the function "_upload" in "webelement.py" 3.change the code of function "_upload", add a condtion in the exception handing part.

def _upload(self, filename):
    fp = StringIO()
    zipped = zipfile.ZipFile(fp, 'w', zipfile.ZIP_DEFLATED)
    zipped.write(filename)
    zipped.close()
    try:
        return self._execute(Command.UPLOAD_FILE, 
                        {'file': base64.encodestring(fp.getvalue())})['value']
    except WebDriverException as e:
        if "Unrecognized command: POST" in e.__str__():
            return filename
        elif "Command not found: POST" in e.__str__():
            return filename
        else:
            raise e

strong text

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.