简体   繁体   English

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

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

I need to test file upload in which I will click upload button and window will be open where I can choose file to be uploaded.我需要测试文件上传,点击上传按钮,window 将打开,我可以在其中选择要上传的文件。 When I click open, file will be automatically uploaded in website.当我点击打开时,文件将自动上传到网站。

This is my RF code这是我的射频代码

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

And this is html code这是 html 代码

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

When I run this code, it will fail because after Choose File, nothing is happening.当我运行此代码时,它将失败,因为在选择文件之后,什么都没有发生。 What should I do to trigger the change upon choosing the file so it will automatically upload?我应该怎么做才能在选择文件时触发更改,以便它自动上传?

Is there a way not to use any other library like autoit or sikuli?有没有办法不使用任何其他库,如 autoit 或 sikuli?

EDIT编辑

I tried to use custom keyword in python but still did not change anything.我尝试在 python 中使用自定义关键字,但仍然没有改变任何东西。 File is not being uploaded automatically.文件未自动上传。

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

EDIT TO ADD UI and HTML Screenshot编辑以添加UI 和 HTML 屏幕截图

I need to test file upload in which I will click upload button我需要测试文件上传,我将在其中单击上传按钮

You should not click the button to activate the operating system file browser.您不应单击该按钮来激活操作系统文件浏览器。

You mentioned click the button, although your code does not show that action.您提到单击按钮,尽管您的代码没有显示该操作。

You should you should see the Javascript session and see what will cause the submit event:您应该看到 Javascript session 并查看导致提交事件的原因:

eg code:例如代码:

I added a example code, replace the choose file with a img in your directory and run it you can see that it works as expected.我添加了一个示例代码,将选择文件替换为您目录中的 img 并运行它,您可以看到它按预期工作。 Now if you check the script session we can see the #fileinput element has a even on(change) that triggers the submit action for this page.现在,如果您检查脚本 session,我们可以看到 #fileinput 元素具有触发此页面提交操作的偶数 on(change)。 Similarly find what triggers the submit action in your case.同样找出在您的案例中触发提交操作的原因。

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