gpt4 book ai didi

python - 通过Python中的selenium驱动程序将图像导入谷歌表单

转载 作者:行者123 更新时间:2023-12-01 07:43:01 24 4
gpt4 key购买 nike

我正在尝试将图像导入谷歌表单。我无法通过 xpath 将 key 传递给元素。看来这是一个隐藏的元素。

我尝试执行脚本来取消隐藏它,但没有成功。也尝试过这个解决方案: How to access hidden file upload field with Selenium WebDriver python

Python-Selenium "input type file" upload

有人有办法通过拖放文件对话框导入谷歌表单吗?

我通常会收到错误:

NoSuchElementException: no such element: Unable to locate element:

我正在发送一些伪代码:

from selenium import webdriver


browser = webdriver.Chrome()




browser.get('ANY GOOGLE FORM URL')


browser.find_element_by_xpath('//*[@id="mG61Hd"]/div/div[2]/div[2]/div[5]/div/div[3]/span/span').click()


fileinput = browser.find_element_by_xpath("//div[contains(@class,'Nf-Er-Xr')]")
fileinput.send_keys('some image path')

最佳答案

点击 Google 表单中的添加文件按钮后,会打开一个弹出窗口,其中 iframeiframe 基本上是嵌入到另一个 HTML 页面中的 HTML 页面。为了使用它,您必须告诉 Selenium 将上下文切换到该 iframe

检查this SO 问题解释了如何将上下文切换到 iframe。对于您的具体情况,即 Google 表单,代码为 ―

iframe = driver.find_element_by_class_name('picker-frame')
driver.switch_to.frame(iframe)
input_field = driver.find_element_by_xpath('//input[@type="file"]')

关于python - 通过Python中的selenium驱动程序将图像导入谷歌表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56595699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com