本文介绍了使用Robot Framework进行自动化测试中的文件上传选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要测试一个特定的场景,在该场景中,需要从本地计算机上的任何文件夹上传文件,并检查是否正确上传了下图所示的文件.我正在使用Robot Framework编写自动化测试脚本以在Chrome浏览器中进行测试

I need to test a particular scenario where I need to upload a file from any folder from my local machine and check whether it gets uploaded correctly as that of below image. I am writing automation testing script using Robot Framework to test in Chrome browser

我正在尝试使用通常用于此方案的选择文件关键字".

I am trying to use Choose File Keyword which is normally used for this scenario.

Test8 To upload a file from Local Drive
Open Browser   http://localhost:35234/    chrome
Select From List By Index            ${transmission drop down}            0
Choose File    ${upload click1}    ${CURDIR}${/}SampleFiles${/}Test.txt

第一行在本地打开我的应用程序.第二行从下拉菜单中选择文件上传"选项.${transmission drop down}保存下拉列表的ID.

First Line opens my application locally.Second line selects File Upload option from drop down.${transmission drop down} holds the ID of the drop down.

然后我正在使用Choose File选项. ${upload click1}选项保存Add Document按钮的xpath值,并且Test.txt文件在提供的相应文件夹中可用.

Then I am using Choose File Option. ${upload click1} option holds the xpath value of Add Document button And Test.txt file is available in the corresponding folder provided.

我不确定我要去哪里哪里,但是我遇到一个奇怪的webdriver错误:

I am not sure where I am going wrong, but I am getting a strange webdriver error:

WebDriverException: Message: u'unknown error: cannot focus element\n  
(Session info: chrome=45.0.2454.93)\n  (Driver info:chromedriver=2.15.322448 
(52179c1b310fec1797c81ea9a20326839860b7d3),platform=Windows NT 6.1 SP1 
x86_64)'

我能够运行其他测试而不会出现此奇怪的错误.我不确定选择文件"是否具有正确的参数.我在哪里出问题了?如果有人可以通过提供示例测试用例来帮助我,那将是很好的.

I am able to run other tests without this strange error.I am not sure whether the Choose File has right parameters. Am I going wrong anywhere? It would be great if someone could help me by providing sample Test Case.

推荐答案

您说${upload click1}具有指向添加文档"按钮的xpath. Choose File的定位符必须是页面上的<input>元素,而不是按钮.

You say that ${upload click1} has the xpath to an "add document" button. The locator for Choose File needs to be to an <input> element on the page, not a button.

这篇关于使用Robot Framework进行自动化测试中的文件上传选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 10:06