Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

selenium - File Upload Option in Automation Testing Using Robot Framework

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

enter image description here

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

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.

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.

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
  
(Session info: chrome=45.0.2454.93)
  (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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...