Ada*_*per 6 webdriver node.js selenium-webdriver webdriver-io
我正在尝试将带有selenium-webdriver gem的Ruby中的以下代码移植到带有WebdriverIO的Node.js:
@webdriver.navigate.to "https://imgur.com/upload"
element = @webdriver.find_element(:id, 'global-files-button')
element.send_keys("C:\\test\\image.png")
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,代码非常简单:导航到URL,找到输入,设置文件路径,并按预期工作,选择要上载的文件.
这是我的移植版本:
describe('User can upload', () => {
it('select file', () => {
browser.url("https://imgur.com/upload");
browser.waitForExist('#global-files-button');
$('#global-files-button').keys("C : \\ t e s t \\ i m a g e . p n g".split(" "));
});
});
Run Code Online (Sandbox Code Playgroud)
不幸的是,这个测试没有设置路径,我无法找到一个使用wdio上传这样的文件的工作示例,文档让我猜测.任何建议非常感谢.
我知道chooseFile和uploadFile,但我正在使用云平台来运行我的wdio测试,但它们似乎无法可靠地工作.
我在这方面遇到了麻烦。根据我的研究,这不是 WebdriverIO 的问题,也不是 choiceFile() 或 uploadFile() 方法的问题。我认为问题的根源在于 Selenium Webdriver 无法处理“多个” <input type='file' multiple>上传元素的错误。
在偶然发现这个 github 问题之前,我为此奋斗了大约 3 天: https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/2239
长话短说,因为 imgur 上的 HTML 具有“multiple”属性,所以您的上传测试将无法正常工作。据我观察,WebdriverIO / Selenium 停止运行。
注意:在测试<input type='file' multiple>. 然而问题是,WebdriverIO 和 Selenium 就停止了。测试结束,不报告任何成功或失败结果。
如果您去测试<input type=file>网络上某个未指定为“多个”上传输入字段的另一个元素,您应该能够使 WebdriverIO 中的 ChooseFile() 方法正确运行。
我希望这对您以及其他在文件上传方面遇到困难的人有所帮助。
编辑:我尝试使您的示例正常工作,并且我成功地使用了“chooseFile()”并将“文件路径”直接传递给它。也许您在不必要的情况下尝试发送键盘命令?您是否有您尝试上传的图像的直接文件路径?以下是我能够用来成功上传文件的内容。
it('upload a file to imgur', function () {
browser.url("https://imgur.com/upload");
browser.waitForExist('#global-files-button');
browser.chooseFile('#global-files-button', '/insert/path/to/image.png')
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3883 次 |
| 最近记录: |