1

I am trying to click a button that brings up a dialogue box to select a file. inspecting the element it looks like its an input rather than a button. Either way I cannot click it with:

element = browser.find_element_by_id("fileupload")
element.click()

and

browser.find_element_by_id("fileupload").send_keys("\n")

Neither of which seem to work.

Here is what I see when I inspect that element on the page:

<span class="btn btn-success fileinput-button">
  <span class="glyphicon glyphicon-upload"></span> 
    Select and Upload...
  <input id="fileupload" name="upfile" accept=".xml" type="file">
</span>

Any assistance help or pointers would be appreciated!

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
gamarga
  • 105
  • 2
  • 7

1 Answers1

2

Clicking on a file input usually triggers a file upload dialog. Since you cannot control it with selenium, you need to avoid the dialog being opened by sending keys to the input instead:

browser.find_element_by_id("fileupload").send_keys("path_to_the_file")

See also:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195