-3

这是我的代码

*** 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
4

2 回答 2

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
于 2017-12-06T10:17:19.287 回答
0

对于 chrome 下面的代码应该可以工作

Choose File    //input[@type='file']    C:/Users/pr.com/Downloads/b.jpg

如果您仍然遇到问题,请告诉我

于 2017-12-06T12:26:11.460 回答