python - 使用带有查找元素的硒上传文件
问题描述
我正在尝试将文件上传到以下网站:kapwing.com/subtitles
我有:
driver=webdriver.Chrome()
driver.get("https://www.kapwing.com/subtitles")
pageSource = driver.page_source
splitted = pageSource.split(" ")
variable = splitted[2119]
final_variable = variable.split('"')[1]
time.sleep(5)
print(final_variable)
driver.find_element_by_id(final_variable).send_keys("/Users/xx/Desktop/lol.mp4")
但它说找不到ID。我将不胜感激任何帮助。
解决方案
如果您尝试单击上传按钮,然后在弹出窗口中输入文件的位置,您将无法在弹出窗口中找到文本框,直到您单击它。
你可以使用这个:
import keyboard
upload_button = driver.find_element_by_xpath('//*[@id="upload-button-input-887ef963-27c3-46cc-8de5-dec5fc340dd7"]')
upload_button.click()
time.sleep(5)
keyboard.write('/Users/xx/Desktop/lol.mp4')
keyboard.press_and_release('return')
推荐阅读
- javascript - Javascript ES6,如果存在则从数组中删除项目的最佳方法,如果不存在则添加
- javascript - 我想每次都在原生反应中重新创建平面列表
- jquery - jQuery,唯一标识
- xml - xml.Unmarshall 多根 XML 在 Go
- grpc - 如何在使用 blazor 的 grpc 调用(或其他异步方法)后使 html 元素显示一个值?
- android - 错误:使用相同的 AVD 运行多个模拟器是 android Studio 中 ubuntu 的实验性功能?
- linq - 从“VisitLambda”调用时,重写“System.Linq.Expressions.ParameterExpression”类型的节点必须返回相同类型的非空值
- excel - 在 word 和格式 para 中查找字符串
- excel - Excel图表动态图表通过订单表格
- python - Django 2.2:将用户模型分解为两个不同的模型?