繁体   English   中英

Selenium Webdriver-由于看不到“添加”按钮,因此无法使用上传功能

[英]Selenium Webdriver - Upload functionality not working due to Add button being invisible

摘要:在Selenium Webdriver中-由于“添加”按钮不可见,因此无法使用上载功能。

描述:

功能类似于,打开一个用于上载文件的弹出窗口,最初禁用添加按钮。 用户需要单击浏览按钮,选择文件,然后系统验证文件格式和大小(4MB)。 如果有效,则浏览文本框将以绿色突出显示。 仅在验证之后,启用“添加”按钮。 单击添加后,弹出窗口关闭,添加的材料显示在主页中。

硒代码和错误:

但是下面的代码会引发错误并显示错误-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">

PLS。 帮助解决此问题。

提前致谢 ....

1秒似乎不足以让“添加”按钮可见。 代替Thread.sleep(1000) ,使用:

WebDriverWait wait = new WebDriverWait(driver, MAX_WAITTIME_IN_SECONDS);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("add_uploadbtn").click();

假定driver.findElementByXPath("//*[@id='fuVideo_ctl02']").sendKeys("D:...正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM