Robot Framework File Upload getting element not reachable error

谁都会走 提交于 2019-12-16 18:04:26

问题


I know this has been answered previously. But I could not find any answer how do I get the locator for the pop up window. I am still getting error while uploading a file from local system to GUI.

  1. In my GUI I clicked on Upload arrow button by giving xpath
  2. Now File upload window pops up and I need to give a file name in the input field either from my desktop or any local path. - *****I am not sure how do I give locator for the input*****
  3. I used Choose File name:File name: C:/Users/xxxx/Desktop/Generic_1902_User_Input_Spreadsheetenter image description here.xlsx

I am getting element is not reachable by keyboard error. Can someone plz upload this video - Check out the video tutorial for Robot Framework File Upload. (Robot Framework File Upload)

Even I tried with AutoIT. I could create an au3 file as well as an exe file. However I am not able to call.use this au3/exe file in my robot framework using Python script.

Can someone plz guide.


回答1:


Do not click on the button that brings up the file chooser window, instead find the <input> element by inspecting the page and use its locator directly with the Choose File keyword.

For example on Stack Overflow, if you want to edit your question and upload an image, the <input type="text" class="s-input" id="image-upload-url-input-55038357"> element should be used. Search for similar element on your page under test.

<div class="grid--cell grid fl-grow1 ai-baseline sm:fd-column sm:ai-stretch d-none js-url-input-container">
  <label class="s-label mr8 sm:mr0 sm:mb4" for="image-upload-url-input-55038357">Paste image or link:</label>
  <div class="fl1 ps-relative">
    <input type="text" class="s-input" id="image-upload-url-input-55038357">
  </div>
  <button class="s-btn sm:as-start js-cancel-url">Cancel</button>
</div>

To give you an example code, the following snippet will navigate to this question as a quest user and will upload a Capture.PNG (without saving). Note the locator //*[contains(@id, 'image-upload-file-input')] for the previous input element.

*** Settings ***
Library           SeleniumLibrary

*** Variables ***
${EDIT QUESTION ELEMENT}    improve this question
${UPLOAD IMAGE BUTTON}    //*[contains(@id, 'wmd-image-button')]

*** Test Cases ***
File Upload Test
    Open Browser    https://stackoverflow.com/questions/55038357/robot-framework-file-upload-getting-element-not-reachable-error    Chrome
    Maximize Browser Window
    Click Link       ${EDIT QUESTION ELEMENT}
    Click Element    ${UPLOAD IMAGE BUTTON}
    Choose File     //*[contains(@id, 'image-upload-file-input')]    D:\\Capture.PNG
    Click Button    Add picture 


来源:https://stackoverflow.com/questions/55038357/robot-framework-file-upload-getting-element-not-reachable-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!