python - 无法使用 selenium 和 Python 将 PDF 从计算机上传到网络
问题描述
我编写此代码以将 PDF 从计算机上传到网站-
uploadPdf = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="lazyAttachCV"]/div/div/div[2]/div/div/div[1]/div[1]/section')))
uploadPdf.click()
使用上面的代码行,我能够打开弹出 的计算机窗口的上传弹出窗口 - 示例
然后我再次编辑代码以从 G 驱动器获取 pdf 文件,代码是
uploadPdf = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="lazyAttachCV"]/div/div/div[2]/div/div/div[1]/div[1]/section'))).send_keys("G://Python Project/Gabi.pdf")
uploadPdf.click()
我尝试使用上面的代码,从 G 驱动器中选择 pdf,但我以回溯错误结束
Traceback (most recent call last):
File "G:\Python Project\Naukri Autamation\main.py", line 39, in <module>
uploadResume = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="lazyAttachCV"]/div/div/div[2]/div/div/div[1]/div[1]/section'))).send_keys("G://Python Project/Gabi.pdf")
File "G:\Python Project\Naukri Autamation\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 477, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT,
File "G:\Python Project\Naukri Autamation\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "G:\Python Project\Naukri Autamation\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "G:\Python Project\Naukri Autamation\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=88.0.4324.104)
我不知道如何编码将pdf从计算机上传到网络,请帮助
解决方案
您不能使用 selenium 与 windows pop 交互而是找到输入标记元素并将文件路径发送到该元素
例如
driver.find_element_by_tag_name("input").send_keys("c://a.pdf")
推荐阅读
- airflow - 本地下载的文件放在 Cloud Composer 的什么位置?
- javascript - 我的 Vue 组件进入无限状态有什么原因吗?
- jquery - 当我从 kendodropdownlist 中选择并将数据发送到函数时,我必须重新加载页面以清除数据
- hibernate - Drools + Hibernate 如何用对象术语编写规则
- python - Selenium 按类和标签查找方法显示不存在任何元素
- excel - 如图所示,如何在 excel 或 powerpoint 上创建间隔均匀的时间线?
- javascript - 通过 find() 过滤 - Javascript
- string - 删除列中的特定字符串值
- php - 教义生命周期回调不适用于 EasyAdminBundle
- spring - spring云数据流http源客户端传凭证