0

I'm attempting to upload a file into a form, but there is no input element with the type of "file".

I'm able to remove the "readonly" attribute and send keys to the input text box, but it throws a general error when I click the upload button. (just a popup with no useful information)

This is the element as presented:

<input type="text" autocomplete="off" class="form-control animate-show 
ng-pristine ng-empty ng-invalid ng-invalid-required ng-touched" 
id="filepath" ng-model="model.name" ng-required="configuration.Required" 
readonly="" required="required" style="">

This is the element after selecting a file manually:

<input type="text" autocomplete="off" class="form-control animate-show 
ng-pristine ng-touched ng-not-empty ng-valid ng-valid-required" 
id="filepath" ng-model="model.name" ng-required="configuration.Required" 
readonly="" required="required" style="">

This is the element after removing "readonly" and sending my file path via selenium:

<input type="text" autocomplete="off" class="form-control animate-show 
ng-touched ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required" 
id="filepath" ng-model="model.name" 
ng-required="configuration.Required" required="required" style="">

Test setup: Ubuntu 20 python 3.8 chrome 91.0.4472.114 selenium 3.141.0

Update: I found the input field below with the type of "file", but it's located at the bottom of the page. (not within the expected modal) Passing the path to this element was successful (no selenium errors), but the upload process still failed.

<label tabindex="-1" style="visibility: hidden; position: absolute; 
overflow: hidden; width: 0px; height: 0px; border: none; margin: 0px; 
padding: 0px;">upload<input type="file" ngf-select="" 
ng-model="model" ng-show="!model"></label> 
"upload" 
<input type="file" ngf-select="" ng-model="model" ng-show="!model"> 
<label tabindex="-1" style="visibility: hidden; position: absolute; 
overflow: hidden; width: 0px; height: 0px; border: none; margin: 0px; 
padding: 0px;">upload 
<input type="file" ngf-select="" ng-model="model" ng-show="!model">
</label>
8
  • 1
    I don't think you can upload file in type="text" input, I think you are supposed to upload file path! There is id that said filepath Commented Jul 17, 2021 at 16:33
  • 1
    Did you try passing the path of the file as input through send keys? and what do you mean by general error? can you share the popup or page url? Commented Jul 17, 2021 at 16:38
  • 1
    You need to check in the entire source html, if any input tag is present with type as file, you can do send_keys(), probably you can check for this css as well , input[type='file'] Commented Jul 17, 2021 at 16:51
  • 2
    can you try with this Xpath ((//input[@type='file'])[1]) I can see you have 3 input tags select based on an index Commented Jul 17, 2021 at 17:18
  • 1
    @YaDavMaNish - It didn't work with index 1, but it did work with 2. Looks like this will work! Thank you so much! Commented Jul 17, 2021 at 17:52

1 Answer 1

1

It turns out there was an element with type="file in a different section of the page. Accessing the correct element and using send_keys with the file path worked perfectly. The original text box in question was populated with the file name and the file upload occurred properly.

Thank you for everyone's input, especially @YaDavMaNish with the syntax that ultimately got this working.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.