Python 使用 selenium phantomjs 上传文件时脚本挂起

Python script hang when uploading a file with selenium phantomjs

我需要使用 selenium 和 phantomjs 上传图像,但只有当我在 firefox 上单击 "upload file" 按钮弹出 "upload file" window 时,才会生成输入字段。

我有一段代码,点击 "upload file" 按钮生成 html 输入字段,然后将图像路径发送给它。

browser.find_element_by_xpath("xpath_to_button").click()
browser.find_element_by_xpath("xpath_to_input_field").send_keys(img_path)

使用 firefox webdriver 它工作正常但是当使用 phantomjs webdriver 时脚本在调用时挂起 send_keys()

我发现这个错误来自 PhantomJS 驱动程序本身,我刚切换到无头 chrome 驱动程序,现在工作正常。