0

Need an input related to uploading a file logic in the Selenium script in headless mode. Implemented Robot class to simulate keyboard commands, but it works only in non-headless mode.

Here is how the upload button looks:

enter image description here

Clicking on upload resume a pop-up window button is displayed. In headless mode after clicking "Upload Resume" button, there is no pop-up window(as per screenshot).

Page Source around the upload button:

<div class="resume_upload_block">
<div id="resumeFile" class="controls-dz dropzone dz-clickable registration_groupl resume_drag_drop">
<div class="dz-default dz-message">
<div class="fa fa-upload"></div>
<label for="file-upload" class="custom-file-upload" title="Upload Resume"> 
<input type="text" name="resume" id="resume" value="" placeholder="Browse *" style=""/>
</label>
</div>
<div class="clearfix">
</div>
</div>
</div>

Looked into options like AutoIT and Sikuli tools. None of the options provided info on how to run in headless mode.

Nik
  • 204
  • 3
  • 20
Sai
  • 1
  • 1
  • Have you tried `webDriver.findElement(By.id("resume")).sendKeys("your/path/to/file")` ? – Minh Dao Dec 26 '19 at 06:37
  • Yes @MinhDao, I did try that option too. `org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of [[ChromeDriver: chrome on XP (dc9bdf7867a80d2afa276eeedfe3c6d9)] -> id: resume] (tried for 15 second(s) with 500 milliseconds interval)` – Sai Dec 26 '19 at 16:10
  • It seems that you're using a WebDriverWait to check if that input is visible. But you might want to check that in DevTool (F12 in FireFox or Chrome). I'm thinking that your `Upload resume` button is actually not the HTML input, and the real input is hidden from the view, that's why you got `TimeoutException`. Could you provide your link so I can take a look? – Minh Dao Dec 27 '19 at 06:48
  • @MinhDao: [Click here](https://goodyear-stg.phenompro.com/us/en/job/GOYEUSenusc2a35a04de3049bfb270c8d4fec5111d/UI-Test-Automation-12-19-2019-16-59-59) Click on Apply --> New User --> you will see upload button. – Sai Dec 27 '19 at 16:29
  • I haven't solved it yet, so I need more time to invest. But I have found this: [Upload file with selenium IDE to Dropzone JS](https://stackoverflow.com/questions/34769506/upload-file-with-selenium-ide-to-the-dropzone-js). Hope this will help you. – Minh Dao Dec 28 '19 at 06:29
  • @MinhDao: tried that option. It did not work. – Sai Dec 30 '19 at 17:15

1 Answers1

0

Sorry for my late answer. After searching a bit, I've found that the real file input isn't under the upload button. Here is the code:

WebElement inputResume = webDriver.findElement(By.className("dz-hidden-input"));
inputResume.sendKeys("/full/path/to/your/file"); // For example: /home/minhdao/Downloads/resume.pdf

I have also create a gist. In case you want a full project that can be executed without configuration, feel free to leave a comment.

Minh Dao
  • 827
  • 8
  • 21
  • thank you for your response. I tried to use the findby with classname you mentioned. Getting StaleElement exception. `org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document` – Sai Jan 20 '20 at 14:44
  • You might find that element before some events happend that make your element disappear (it's called re-rendering DOM). I have uploaded a git repo with complete code: [TestUploadFile](https://github.com/daoducminh/TestUploadFile). There is a simple guide to run this project in `README.md` file. If there is any problem, feel free to create an issue in: [Issues](https://github.com/daoducminh/TestUploadFile/issues) – Minh Dao Jan 21 '20 at 02:39