如何使用python硒上传带有角度分量的图像 [英] How to upload image with angular components using python selenium
问题描述
我的自动化脚本需要将图像上传到网页,但是我似乎无法使用常规的send_keys方法上传图像.我怀疑它与Angular组件有关,但是我不确定如何使用Selenium Webdriver访问它们.
我尝试了以下方法:使用Selenium和ng-file-upload自动上传文件和如何使用python + selenium上传文件?
这些似乎没有我正在寻找的解决方案.
< button class ="md-提升的选择文件md-button md-ink-ripple ng-empty ng-valid" type ="button" ng-transclude =" ngf-select ="accept ="image/*" ng-model ="vm.uploader.original" aria-invalid ="false">选择文件</button>
我没有任何错误,因为我可以成功找到元素,但是图像没有上传/发送.
file_input.send_keys("/位置/图片/profile_student.jpg")
要处理Windows对象,可以使用 autoit
.但是 AutoItX3.dll
有Python绑定>
您需要使用pip安装 PyAutoIt
.
pip install -U pyautoit
您需要在python脚本上自动导入.
自动导入
首先单击选择文件
按钮.
driver.find_element_by_xpath("//button [@ type ='button'] [包含(.,'Choose file')]").click()
然后添加以下代码以及相关文件路径
filepath ="C:\\ filelocation \\ filename.jpg"autoit.win_wait_active(文件上传",5)如果autoit.win_exists(文件上传"):autoit.control_send(文件上传","Edit1",文件路径+"{ENTER}")
如果您需要进一步的帮助,请告诉我.
My automation script needs to upload an image to the webpage but I can't seem to upload the image using the normal send_keys method. I suspect it has something to do with the Angular components but I'm not sure how to access them using Selenium webdriver.
I have tried the following: Automate file upload using Selenium and ng-file-upload and How to upload file using python+selenium?
These don't seem to have the solution I'm looking for.
<button class="md-raised choose-file md-button md-ink-ripple ng-empty ng-valid" type="button" ng-transclude="" ngf-select="" accept="image/*" ng-model="vm.uploader.original" aria-invalid="false">Choose file</button>
I don't have any errors because I can successfully locate the element but the image is not uploaded/sent.
file_input.send_keys("/location/of/image/profile_student.jpg")
To handle windows object you can use autoit
However there is Python binding for AutoItX3.dll
You need to install PyAutoIt
using pip.
pip install -U pyautoit
You need to import autoit on your python scripts.
import autoit
Click on the chose file
button first.
driver.find_element_by_xpath("//button[@type='button'][contains(.,'Choose file')]").click()
Then add the following code with the relevant file path
filepath="C:\\filelocation\\filename.jpg"
autoit.win_wait_active("File Upload",5)
if autoit.win_exists("File Upload"):
autoit.control_send("File Upload","Edit1",filepath+"{ENTER}")
Let me know if you need further assistance.
这篇关于如何使用python硒上传带有角度分量的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!