繁体   English   中英

选择文件成功执行但没有在机器人框架中上传文件

[英]Choose File executes successfully but does not upload file in Robot Framework

我需要测试文件上传,点击上传按钮,window 将打开,我可以在其中选择要上传的文件。 当我点击打开时,文件将自动上传到网站。

这是我的射频代码

Wait Until Page Contains Element     css=[type='file']
Scroll Element Into View             css=[type='file']
Choose File                          css=[type='file']     C:\\tests\\upload\\example.png
Wait Until Page Contains             File uploaded

这是 html 代码

<div class="upload">
   <div><input class="uploadinput" type="file" name="file">Upload File</div>
</div>

当我运行此代码时,它将失败,因为在选择文件之后,什么都没有发生。 我应该怎么做才能在选择文件时触发更改,以便它自动上传?

有没有办法不使用任何其他库,如 autoit 或 sikuli?

编辑

我尝试在 python 中使用自定义关键字,但仍然没有改变任何东西。 文件未自动上传。

def choose_upload(self, locator, file_paths):
  sl = BuiltIn().get_library_instance('SeleniumLibrary')
  sl.find_element(locator).send_keys(file_paths)

编辑以添加UI 和 HTML 屏幕截图

我需要测试文件上传,我将在其中单击上传按钮

您不应单击该按钮来激活操作系统文件浏览器。

您提到单击按钮,尽管您的代码没有显示该操作。

您应该看到 Javascript session 并查看导致提交事件的原因:

例如代码:

我添加了一个示例代码,将选择文件替换为您目录中的 img 并运行它,您可以看到它按预期工作。 现在,如果您检查脚本 session,我们可以看到 #fileinput 元素具有触发此页面提交操作的偶数 on(change)。 同样找出在您的案例中触发提交操作的原因。

*** Settings ***
Documentation       Robot Framework Example
Library             SeleniumLibrary
Library             BuiltIn
Library             OperatingSystem
Suite Teardown      Close Browser

*** Variables ***

*** Test Cases ***
My Testq
    Open Browser    https://codepen.io/jhoel18/pen/yyLeWv
    Select Frame    css=#result 
    ${a}=     Get Webelement     css=#filesToUpload
    Choose File    css= #filesToUpload    C:\\Users\\prave\\Downloads\\travelBA\\selenium-screenshot-1.png 
    Sleep    100000

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM