Andersson
Andersson

Reputation: 52665

How to send text to invisible input field

I need to automate file uploading.

Here is a HTML code for path-to-file input field and button for manual uploading:

<div class="ctrl_div">
     <input id="fileupload" class="hid" name="files" accept="application/zip" data-url="/Server/file/upload" type="file">
     <button id="fileBtn" class="btn btn-primary" type="button">Upload</button>
</div>

When I try

driver.find_element_by_xpath('//input[@id="fileupload"]').send_keys(path_to_file)

I get ElementNotVisibleException

I also tried

driver.execute_script("document.getElementById('fileupload').style.visibility = 'visible';")

But input field remains invisible for webdriver.

Any ideas?

P.S. Adding implicit/explicit wait will not make a trick

Upvotes: 0

Views: 284

Answers (1)

fabdurso
fabdurso

Reputation: 2444

You should try with

driver.execute_script(document.getElementById('fileUpload').style.display='bloc‌​k';");

Upvotes: 1

Related Questions