Javascript 文件上传的自动化

Javascript 文件上传的自动化,javascript,python,selenium,selenium-chromedriver,browser-automation,Javascript,Python,Selenium,Selenium Chromedriver,Browser Automation,我正在尝试使用Selenium、python和ChromeWebDriver将文件自动上传到Facebook对话框。以下是代码: driver.get("https://www.facebook.com/messages/t/1231231242314") js = "document.querySelectorAll('input[type=\"file\"]')[0].setAttribute('class', '')" driver.execute_script(j

我正在尝试使用Selenium、python和ChromeWebDriver将文件自动上传到Facebook对话框。以下是代码:

    driver.get("https://www.facebook.com/messages/t/1231231242314")
    js = "document.querySelectorAll('input[type=\"file\"]')[0].setAttribute('class', '')"
    driver.execute_script(js)
    driver.find_elements_by_css_selector("input[type='file']")[0].send_keys("d:\local.jpg")
    js = "document.querySelectorAll('input[type=\"file\"]')[0].parentNode.parentNode.submit()"
    driver.execute_script(js)
我正在删除元素的类,它可以通过send_keys()方法访问。然后将输入元素的设置值send_keys()发送到“d:\local.jpg”,它就可以工作了。但当表单提交什么都没有发生时,只需重定向到https://upload.facebook.com/ajax/mercury/upload.php。如何上传文件

顺便说一句,很抱歉英语不好