简体   繁体   English

使用 selenium 在隐藏输入上上传图像

[英]Upload an image on a hidden input using selenium

This question has been asked many times over the years but all the answers I've found have been outdated.多年来,这个问题已经被问过很多次,但我找到的所有答案都已经过时了。

With modern websites, the input element tends to be hidden.对于现代网站,输入元素往往是隐藏的。 I'm trying to upload a file to a social media platform as the profile picture.我正在尝试将文件作为个人资料图片上传到社交媒体平台。 I've tried finding the hidden input element and entering the file directory of the png/jpg but no luck.我试过找到隐藏的输入元素并输入 png/jpg 的文件目录,但没有运气。

I don't want to use libraries like pyautogui because I want the program to run fully automatously in the background of the users computer.我不想使用像pyautogui这样的库,因为我希望程序在用户计算机的后台全自动运行。

The upload is covered by an <svg> and underneath there is a <label> & <input> .上传由<svg>覆盖,下面有一个<label> & <input>

Thanks in advance提前致谢

Have you tried sending the file you trying to upload with this command:您是否尝试过使用此命令发送您尝试上传的文件:

driver.find_element_by_xpath("//input[@type='file']").send_keys(the_path_to_the_file_on_your_pc)

? ?

It's inputting the file but the croppable image doesn't show up它正在输入文件,但可裁剪的图像不显示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM