0
votes

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.

1
Have you tried webDriver.findElement(By.id("resume")).sendKeys("your/path/to/file") ? - Minh Dao
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
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
@MinhDao: Click here Click on Apply --> New User --> you will see upload button. - Sai
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. Hope this will help you. - Minh Dao

1 Answers

0
votes

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.