自动上传锚标签的文件方案



我正在尝试自动化行为,该行为具有与文件上传有关的多种情况,并具有不同的断言组合。在UI中有一个锚标记,而不是输入标签,为什么我不能使用send jeys来上传文件。我不想使用autoit,sikuli喜欢工具,因为它们与云环境上的远程执行不兼容并添加额外的库负债。

这是一个Angular JS应用程序,DOM代码为

----" a href =" javaScript:void(0(" title =" peals file to上载class =" btn btn btn-blue" ng-show =" fileuploadsubitting" uploadfileattachment(("

我尝试找到: - 1:Angular JS库的任何instruild上传函数,以便我可以通过JavaScript执行程序执行它。2:Sikuli和Autoit正在工作,但这将是最后的解决方案3:尝试编辑标记名称以输入使用DOM中的类型文件,然后是SendKeys,但它行不通

您可以尝试以下方法。

Tested locally not on the server.
# get the button element
ele = driver.find_element_by_id("file_input_btn")
# add a hidden file input ( might have to change the onchange event based on the events associated to the button in above line as you don't have a form)
driver.execute_script("var x=  document.createElement('INPUT');x.setAttribute('type', 'file'); x.setAttribute('onchange','this.form.submit()');x.setAttribute('hidden', 'true'); arguments[0].appendChild(x);",ele)
# send the file path here ( this should upload the file)
driver.find_element_by_xpath("//input[@type='file']").send_keys("file path should go here")

最新更新