I am currently facing a challenge with automating a file upload process in a client web application. The code snippet for the file upload form is provided below:
<td valign="top">
<iframe id="batchLoad:inputFile:uploadFrame" class="iceInpFile" width="600px" scrolling="no" height="30px" frameborder="0" title="Input File Frame" style="border-collapse:collapse; border-spacing:0px; padding:0px;" src="/hip-webapp/block/resource/LTExMzg4MjQzMTY=/" name="batchLoad:inputFile:uploadFrame" marginwidth="0" marginheight="0" allowtransparency="true">
<html style="overflow:hidden;">
<head>
<body style="background-color:transparent; overflow:hidden">
<form id="fileUploadForm" enctype="multipart/form-data" action="/hip-webap/uploadHtml" method="post">
<input type="hidden" value="batchLoad:inputFile" name="ice.component">
<input type="hidden" value="3" name="ice.view">
<input class="iceInpFileTxt" type="file" size="35" name="upload">
<input class="iceInpFileBtn" type="submit" value="Upload">
</form>
</body>
</html>
</iframe>
<br>
<span id="batchLoad:j_id537"></span>
</td>
My attempt to use the traditional file upload method was unsuccessful.
For reference, please see: Selenium Webdriver File Upload error element ice:inputFile
My lack of familiarity with JavaScript leads me to believe that I may be making a syntax error. The approach I tried is outlined below:
String ew = (String)js.executeScript("document.getElementByXPath('//form[@id='fileUploadForm']/input[3]')");
String j = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
js.executeScript(j, ew);
I found some guidance here: Selenium WebDriver clicking on hidden element.
However, I am currently encountering a syntax error. I used Selenium IDE to obtain the XPath. I also attempted the following alternatives, which did not yield the desired outcome:
((JavascriptExecutor)driver).executeScript("document.getElementByClassName(iceInpFileTxt).style.visibility = 'visible';");
((JavascriptExecutor)driver).executeScript("document.getElementByClassName('iceInpFileTxt').value = 'D:\\AD\\Prac\\Prac\\002 EditPrac Add Person Error.xml-revHEAD.svn000.tmp.xml'");
Any advice or recommendations would be greatly appreciated.