0

I am new automation and I am using selenium with python and got stuck.

I am trying to upload the document using sendkeys in selenium but getting this error.

Error -selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element.

Section where i am trying to upload the document ::

Upload document GUI

Below is the html code:

<spane class="uk-form-file md-btn" style="width:70%;height: 50%">
                                                Upload Document
<input type="file" ngf-select="" id="picture_ids" class="md-input ng-pristine ng-invalid ng-invalid-required ng-touched" onchange="angular.element(this).scope().imageUpload(this.files,'picture','document')" name="picture" ng-model="statusUpdate.document" style="width: 100%;" ng-required="true" required="required">
<br>
</spane>

and corresponding Selenium code:

uploaddoc=wait.until(EC.presence_of_element_located((By.XPATH, "//spane[@class='uk-form-file md-btn']")))
uploaddoc.send_keys("C:/PycharmProjects/Auc/dummy.pdf")
  • Your HTMl code has syntax error its like <spane>. Is there any <spane/> tag actual sytax is <span/> – Mohamed Sulaimaan Sheriff Aug 21 at 10:00
  • Thanks @MohamedSulaimaanSheriff – Suresh Kumar Aug 21 at 10:47
2

You are trying to sendKEys to a span element ,

instead you have to use input element.

try using :

uploaddoc=wait.until(EC.presence_of_element_located((By.XPATH, "//input[@id='picture_ids']")))
uploaddoc.send_keys("C:/PycharmProjects/Auc/dummy.pdf")
| improve this answer | |
  • 1
    thanks @PDHide . its working. – Suresh Kumar Aug 21 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.