I am trying to automate a file upload scenario in a client web application. The code of the entire file upload form looks like this
<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>
I tried with the conventional File upload method, but that did not work.
Please refer: Selenium Webdriver FIle Upload error element ice:inputFile
I am not much familiar with Javascript hence I think I am doing some syntax error. What I tried is:
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);
Got the hint from here Selenium WebDriver clicking on hidden element.
But now I am getting syntax error. I got the XPath using Selenium IDE. I have also tried this, but that did not work either.
((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'");
Please advice.