[英]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.