【发布时间】:2014-04-04 10:37:21
【问题描述】:
总结: 在 Selenium Webdriver 中 - 由于“添加”按钮不可见,上传功能无法正常工作。
说明:
功能就像,一个弹出窗口打开上传文件,最初添加按钮是禁用的。用户需要点击浏览按钮,选择文件,系统会验证文件格式和大小(4MB)。如果其有效,则浏览文本框以绿色突出显示。仅在验证后,添加按钮才会启用。单击添加后,弹出窗口关闭,添加的材料显示在主页中。
Selenium 代码和错误:
但下面的代码会抛出错误并出现错误 - org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与之交互。
driver.findElementByXPath("//*[@id='fuVideo_ctl02']").sendKeys("D:\\Featured Materials");
Thread.sleep(1000);
driver.findElementByClassName("add_uploadbtn").click(); //Clicking on Add button
String Addtext = driver.findElementByClassName("add_uploadbtn").getText();
System.out.println("添加文本" +Addtext);
以上打印语句结果: 添加文字
注意:当脚本运行时,文件被上传,文件验证开始但没有结束。它会显示一段时间,脚本以上述错误结束。
HTML: 上传功能代码直到添加按钮
<td colspan="2">
<span id="fuVideo" class="upload_file_txt mleft10" style="background: white" onclick="javascript:fnCheckFileIsUpload(this);">
<input id="fuVideo_ctl00" class="upload_file_txt" type="hidden" name="fuVideo$ctl00" style="width: 550px;" value="Copy of CAS QEA-PES Score Card Feb_2014_Capex Opex_STORM_Updated.xlsx">
<div id="fuVideo_ctl01" name="fuVideo_ctl01">
<input id="fuVideo_ctl02" class="upload_file_txt" type="file" style="width: 550px; background-color: Lime; color: black;" name="fuVideo$ctl02">
</div>
</span>
<br disabled="disabled">
<span style="margin-left: 25px;">Description</span>
<input id="txtDescriptionFU" class="add_edit_content_input" type="text" style="margin-left: 20px; width: 460px;" maxlength="500" name="txtDescriptionFU">
<input id="btnVideo" class="add_uploadbtn" type="button" onclick="javascript:fnFileUploadValidation();" value="Add">
请。帮助解决这个问题。
在此先感谢....
【问题讨论】:
标签: java user-interface file-upload selenium