【问题标题】:Is it possible to use Choose File in Robot Framework to Choose a folder?是否可以使用 Robot Framework 中的选择文件来选择文件夹?
【发布时间】:2019-10-12 01:37:39
【问题描述】:

我想知道是否可以通过一些参数使用选择文件关键字来选择文件夹而不是单个文件?

文件上传输入的 HTML 类似于我们应用程序中的文件夹上传输入。

文件

<input data-automation-id="upload-multiple-files" id="upload-multiple-files" multiple="multiple" name="uploadFiles" type="file" accept="*" title="Select files to upload">

文件夹

<input data-automation-id="uploadFolder" directory="" id="uploadFolder" multiple="multiple" name="uploadFiles" type="file" webkitdirectory="" accept="*" title="Select folders to upload">

对于文件上传Choose File xpath=//input[@type="file"] C:\\Users\\username\\Desktop\\robottestfile.txt 有效。但是对于文件夹上传 Choose File xpath=//input[@type="file"] C:\\Users\\username\\Desktop\\ 没有。

很抱歉,如果这有一个简单的解决方案,我还没有找到。

尝试了 Helios 的答案,它把我带到了一个新的地方。

现在我有

Send folder
    @{my_file_list}=    OperatingSystem.List Files In Directory    ${path_to_directory}
    FOR    ${file}    IN    @{my_file_list}
    \    ${result}=    Choose File    ${my_locator}    ${file}
# Finish this test
#     Close Browser  
*** Keywords ***

*** Variables ***
${my_locator}  xpath=//input[@title="Select files to upload"]
${path_to_directory}  C:\\Users\\username\\Desktop\\alfrescotestfolder

但我收到此错误:

ValueError:本地文件系统上不存在文件“alfresctotestexcel.xlsx”。

alfrescotestexcel.xlsx 在那个目标文件夹中...

【问题讨论】:

    标签: robotframework


    【解决方案1】:

    不,Choose File 没有现成的解决方案。您必须获取文件夹中的文件名,然后为每个文件获取 Choose File

    @{my_file_list}=    OperatingSystem.List Files In Directory    ${path_to_directory}
    : FOR    ${file}    IN    @{my_file_list}
    \    ${result}=    Choose File    ${my_locator}    ${path_to_directory}${/}${file}
    

    【讨论】:

    • 谢谢!为我打开了一个全新的世界。
    【解决方案2】:
        @{my_file_list}=    OperatingSystem.List Files In Directory    C:\\Users\\Desktop\\My pics
        FOR    ${file}    IN    @{my_file_list}
            ${result}=    Choose File    //input[@type="file"]    C:\\Users\\Desktop\\My pics\\${file}
            Wait Until Keyword Succeeds    120    2s    Element Should Be Visible    ${xpath_for_BrowseFiles_button}
        END
    

    我在文件选择中添加了完整路径。请试试这些,这对你有用。

    注意: 如果您有“浏览文件”或“选择文件”按钮,请使用此行等待关键字成功 120 2s 元素应该可见 ${xpath_for_BrowseFiles_button}。

    【讨论】:

    • 也谢谢你!这解决了问题!
    猜你喜欢
    • 2017-08-16
    • 2014-03-13
    • 2020-02-15
    • 2022-12-02
    • 2011-04-25
    • 2023-03-22
    • 2020-01-31
    • 2016-10-08
    • 1970-01-01
    相关资源
    最近更新 更多