需要有关隐藏文件上传元素的 webdriver 和 Javascript 的帮助 [英] Need help for webdriver and Javascript for a hidden File upload element

查看:22
本文介绍了需要有关隐藏文件上传元素的 webdriver 和 Javascript 的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在客户端 Web 应用程序中自动执行文件上传方案.整个文件上传表单的代码是这样的

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.

请参考:Selenium Webdriver 文件上传错误元素 ice:inputFile

我对 Javascript 不太熟悉,因此我认为我在做一些语法错误.我试过的是:

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);

从这里得到提示 Selenium WebDriver 点击隐藏元素.

但是现在我遇到了语法错误.我使用 Selenium IDE 获得了 XPath.我也试过这个,但也没有用.

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'");

请指教.

推荐答案

因为您正在使用的页面上有一个