这是我的代码
*** 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:Userspr.comDownloadsb.jpg
这是结果
Test
| FAIL |
File 'C:{/}Userpr.comDownloadbase.png' does not exist on the local file system
我使用:
Python version 2.7.14
Robotframework ride 1.5.2.1
来自文档
http://robotframework.org/robotframework/latest/libraries/operatingsystem.html
因为机器人框架将Backslash('')用作测试数据中的逃生字符,因此使用字面的后斜线需要像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
对于代码下方的铬
Choose File //input[@type='file'] C:/Users/pr.com/Downloads/b.jpg
让我知道您是否仍然有问题