Re: [selenium-users] File Input using Grid on a ZK webapp

421 views
Skip to first unread message

Krishnan Mahadevan

unread,
Jul 31, 2012, 7:28:14 AM7/31/12
to seleniu...@googlegroups.com
Ricardo,

Can you try if the below works ?

RemoteWebElement element = (RemoteWebElement) driver.findElementByName("file");
element.setFileDetector(new LocalFileDetector());
element.sendKeys(new File("/path/to/file.png").getAbsolutePath());


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



On Tue, Jul 31, 2012 at 4:45 PM, Road Runner <rjl...@gmail.com> wrote:
I've been using Selenium Grid to automate testing on a webapp created using the ZK framework without much problems (except for the random ID's that make locating elements a pain), but now I'm facing a problem I'm not being able to solve, which is File Uploads.

In other file upload forms I've used the following code with success:

LocalFileDetector detector = new LocalFileDetector();
File file = detector.getLocalFile("/path/to/file.png");
driver
.setFileDetector(detector);
driver
.findElementById("id_of_file_input").sendKeys(file.getAbsolutePath());


This sends the file to the node, saves it on a temporary location and fill the form with that temp location. Happy times. Now when I do the same but to a file input form of a ZK generated application, the file is sent to the node, but the form stays empty. Since there's a validation to make sure the form is not empty, I cannot proceed. Looking at the HTML I can see that there's an input field followed by a Browse button, and then there's a hidden form with another file input:

<...>
<input id="g1sWf4" class="value-field z-textbox z-textbox-real-readonly z-textbox-readonly" type="text" readonly="readonly" value="" style="width:130px;">
<...>
<form method="POST" enctype="multipart/form-data">
   
<input type="file" style="height: 22px; clip: rect(auto, auto, auto, 1143px);" hidefocus="true" name="file">
</form>
<...>

Any ideas how I can do a file upload in this scenario?

Ricardo Loureiro

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/tKd9yKiyXq8J.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Road Runner

unread,
Jul 31, 2012, 8:49:16 AM7/31/12
to seleniu...@googlegroups.com
Hi Krishnan,

I was trying sentKeys in the hidden element like you suggested and was getting element not clickable (not sure why). Meanwhile I just managed to get it working with the following code:

LocalFileDetector detector = new LocalFileDetector();
File file = detector.getLocalFile("/home/rjlouro/Downloads/bmw_535d.jpg");
driver
.setFileDetector(detector);
driver
.findElementByName("file").sendKeys(file.getAbsolutePath());

Which is pretty much what you suggested. I'm not sure why I was getting the element not clickable error, and what I did to solve it, but with the above code it's working! Thanks a lot for the suggestion.

Ricardo Loureiro
To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

Road Runner

unread,
Jul 31, 2012, 1:07:08 PM7/31/12
to seleniu...@googlegroups.com
Update, seems that my code only works on Firefox, while Krishnan's code works on Firefox and Internet Explorer. Unfortunately neither of them run on chrome, I get the following error:

org.openqa.selenium.WebDriverException: Element is not clickable at point (84, 418.5). Other element would receive the click: <div id="p7IQj2-mask" class="z-modal-mask" style="z-index: 1800; left: 0px; top: 0px; width: 1040px; height: 665px; display: block; "></div>

I searched a bit, found a similar issue but not with file input (http://code.google.com/p/selenium/issues/detail?id=2766), and the workarounds did not solve it. Any ideas?

Ricardo Loureiro

David

unread,
Jul 31, 2012, 6:10:41 PM7/31/12
to seleniu...@googlegroups.com
I was wondering, is the file upload performed against the file input element, or a hidden input element. We know the user browsing for the file is via the file input, but the value selected can then be set elsewhere (with javascript) and used however via javascript. If it's done non-standard w/ upload not actually taken and performed against the file input element, then it can be tricky to automate. Your app developers probably know the details.

Here's an example about related tricky situations: we have app that uses HTML5 uploader. It's uses standard file input element (but supports multiple file selection via the browser select file GUI) and thus supports multiple file upload. The upload is actually performed by javascript and XmlHttpRequests for each file to upload performed in parallel upload sets of 3, and doesn't use a standard form submission for upload. As such, there's no direct support for this with WebDriver, I was only able to make the uploader upload a single file via sendKeys (whether remote in Grid or local), tried various sendKeys to send CSV string or space delimited string with files quoted as needed, and it just didn't work. I have feeling I could workaround this by set value of file input element manually (via javascript) and then trigger javascript upload function, but unfortunately, browser security prevents you from programmatically setting value of a file input element.

Road Runner

unread,
Aug 1, 2012, 5:50:13 AM8/1/12
to seleniu...@googlegroups.com
The file upload is against the hidden form, that's why chrome is not handling it. In this case I believe it's a problem with the chrome driver, and by reading the error message it seems that chrome translates elements to coordinates (Element is not clickable at point (84, 418.5). Other element would receive the click, and since the form input is not visible it would click on the visible element present at that location.

This does not seem to be the case with IE or firefox, both are able to use the hidden form. Since Chrome does not have a significant market share at this point, I'm skipping this test with Chrome, but I'll be  digging with the developers through the ZK implementation of file uploads to understand how it's done.

Ricardo Loureiro
Reply all
Reply to author
Forward
0 new messages