这是我的代码
*** Settings ***
Library Selenium2Library
*** Variables ***
${Login} xpath=/html/body/app/main/login/div/div[1]/div/form/div[3]/div/button
*** Test Cases ***
Test
OPEN
LOGIN
Sleep 5s
ADD TOPIC
Sleep 2s
SelectType
TypePDF
Sleep 5s
AddFile
*** Keywords ***
OPEN
Open Browser https://********** \ \ \ googlechrome
LOGIN
Input Text id=inputEmail3 ********
Input Text id=inputPassword3 *******
Click Element xpath=/html/body/app/main/login/div/div[1]/div/form/div[3]/div/button
ADD TOPIC
Click Element xpath=/html/body/app/main/pages/div/div/news/div/news-list/button
SelectType
Click Element id=selectType
TypePDF
Click Element xpath=//*[@id="selectType"]/option[5]
AddFile
Click Button xpath=/html/body/app/main/pages/div/div/news/div/news-add/ba-card/div/div[2]/div[2]/div[1]/div[2]/ba-file-uploader/div/span/button
Sleep 2s
Choose File <input type="file" id="myFile"> C:{/}User${/}pr.com${/}Download${/}base.png
Addpicture
Choose File //input[@type='file'] C:\Users\pr.com\Downloads\b.jpg
这是结果
Test
| FAIL |
File 'C:{/}User\pr.com\Download\base.png' does not exist on the local file system
我用:
Python version 2.7.14
Robotframework ride 1.5.2.1
答案 0 :(得分:1)
来自文件
http://robotframework.org/robotframework/latest/libraries/OperatingSystem.html
因为Robot Framework使用反斜杠('\')作为测试数据中的转义字符,所以使用文字反斜杠需要像r'c:\ path \ file.txt中那样复制它。 “
因此,当您提供文件路径
时,请使用“\”双斜杠如果仍然无效,请检查您提供的路径是否存在
*** Settings ***
Library Selenium2Library
Library OperatingSystem
*** Test Cases ***
Test
Open Browser and login
*** Keywords ***
Open Browser and login
File Should Exist C:\\Users\\pr.com\\Downloads\\b.jpg
答案 1 :(得分:0)
对于以下代码的chrome应该可以正常工作
Choose File //input[@type='file'] C:/Users/pr.com/Downloads/b.jpg
如果您仍然遇到问题,请告诉我