简体   繁体   English

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

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

Summary: In Selenium Webdriver - Upload functionality is not working due to Add button being invisible. 摘要:在Selenium Webdriver中-由于“添加”按钮不可见,因此无法使用上载功能。

Description: 描述:

The functionality is like, a pop up window opens for upload file, initially Add button is disable. 功能类似于,打开一个用于上载文件的弹出窗口,最初禁用添加按钮。 The user needs to click on browse button, select the file and the system validates for the file format and size (4MB). 用户需要单击浏览按钮,选择文件,然后系统验证文件格式和大小(4MB)。 If its valid then the browse text box is highlighted in green. 如果有效,则浏览文本框将以绿色突出显示。 After validation only, Add button gets enabled. 仅在验证之后,启用“添加”按钮。 On clicking Add, pop up closes and added material is displayed in main page. 单击添加后,弹出窗口关闭,添加的材料显示在主页中。

Selenium Code and Error: 硒代码和错误:

But below se code throws error with the error - org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with. 但是下面的代码会引发错误并显示错误-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("Add text" +Addtext); System.out.println(“添加文本” + Addtext);

Above Print Statement Result: Add text 在打印语句上方结果:添加文本

Note: While the script is running, document is uploaded and file validation starts and doesnt end..its showing for sometime and scripts ends with above mentioned error. 注意:在脚本运行时,会上载文档,并且文件验证不会开始,也不会结束。显示一段时间,脚本以上述错误结束。

HTML: Upload functionality code till Add button 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. PLS。 help to solve this issue. 帮助解决此问题。

Thanks in Advance .... 提前致谢 ....

1 second doesn't seem like enough time for the Add button to become visible. 1秒似乎不足以让“添加”按钮可见。 Instead of Thread.sleep(1000) , use: 代替Thread.sleep(1000) ,使用:

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

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

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

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