使用硒化物来进行反应应用程序记录测试用例,但是无法从硒化物中上传文件。 React-dropzone软件包用于文件上传。
尝试使用命令“类型”和“发送密钥”,但无效。
硒化物:3.6.0 铬:74.0.3729.108
尝试使用Firefox,但收到错误消息“目前仅支持Chrome上传文件”
Command: type
Target: css=input[type=file]
Value: c:\fakepath\test.png
Error: {"code":-32000,"message":"Not allowed"}
Command: send keys
Target: css=input[type=file]
Value: c:\fakepath\test.png
Error: Element is not currently interactable and may not be manipulatedElement is not currently interactable and may not be manipulated
Selenium ide能够上传文件并通过测试用例。
答案 0 :(得分:2)
在Chrome上,您可以转到: 窗口>更多工具>扩展> Selenium IDE>详细信息
然后打开“允许访问文件URL”选项。
我遇到了同样的问题,这对我有用。
答案 1 :(得分:0)
尝试使用Firefox,但收到错误消息“目前仅支持Chrome上传文件”
此问题与React或SIDE无关。支持从扩展程序内部文件上传的所有 浏览器扩展程序(例如iMacros,SIDE等)都是通过Chrome调试API来完成的。 Firefox没有这样的扩展API =>无法自动上传文件。
解决方案:使用Kantu Selenium IDE。它使用外部的本机帮助程序(称为“ XModules”)克服了这些限制,因此也支持automating file uploads in Firefox。
Chrome 的测试宏:
{
"Name": "1upload",
"CreationDate": "2019-5-2",
"Commands": [
{
"Command": "open",
"Target": "https://cgi-lib.berkeley.edu/ex/fup.html",
"Value": ""
},
{
"Command": "XClick",
"Target": "name=upfile",
"Value": ""
},
{
"Command": "XType",
"Target": "C:\\1tmp\\1test.txt",
"Value": ""
},
{
"Command": "XType",
"Target": "${KEY_ENTER}",
"Value": ""
},
{
"Command": "clickAndWait",
"Target": "xpath=/html/body/form/input[3]",
"Value": ""
}
]
}
Firefox
的测试宏在这里XType | ${KEY_ENTER}
不起作用(我不确定为什么)。因此,我用 x 替换了它,方法是使用desktop automation单击“打开”按钮。使用的图像是:
{
"Name": "1upload-firefox",
"CreationDate": "2019-5-2",
"Commands": [
{
"Command": "open",
"Target": "https://cgi-lib.berkeley.edu/ex/fup.html",
"Value": ""
},
{
"Command": "XClick",
"Target": "name=upfile",
"Value": ""
},
{
"Command": "XType",
"Target": "C:\\1tmp\\1test.txt",
"Value": ""
},
{
"Command": "comment",
"Target": "XType // ${KEY_ENTER}",
"Value": ""
},
{
"Command": "XDesktopAutomation",
"Target": "true",
"Value": ""
},
{
"Command": "XClick",
"Target": "1test_dpi_96.png@0.6",
"Value": ""
},
{
"Command": "clickAndWait",
"Target": "xpath=/html/body/form/input[3]",
"Value": ""
}
]
}