Selenium 访问iframe中的文件对话框
我有一个内联jsp页面,其中包含html类型:file的代码。下面显示的IFRAME标记位于主jsp中。我想传递文件名并使用web驱动程序提交此文件对话框。基本上,我想做一些事情,比如:Selenium 访问iframe中的文件对话框,selenium,selenium-webdriver,Selenium,Selenium Webdriver,我有一个内联jsp页面,其中包含html类型:file的代码。下面显示的IFRAME标记位于主jsp中。我想传递文件名并使用web驱动程序提交此文件对话框。基本上,我想做一些事情,比如: WebElement elem = driver.findElement(By.id("attachmentfile")); elem.sendKeys("C:\\Users\\Public\\Pictures\\Sample Pictures\\Koala.jpg"); 但是,我无法获得附件
WebElement elem = driver.findElement(By.id("attachmentfile"));
elem.sendKeys("C:\\Users\\Public\\Pictures\\Sample Pictures\\Koala.jpg");
但是,我无法获得附件文件id。如有任何帮助,将不胜感激。谢谢
主要Jsp:
<IFRAME id=fileupload src="fileupload.jsp?type=uploadbutton"
frameBorder=0></IFRAME></TD></TR></FORM>
fileupload.jsp如下所示:
<html> <body>
<form name="frm_fileUpload" ENCTYPE="multipart/form-data"><%
<tr>
<td>
<input type="file" name="attachmentfile"
id="attachmentfile" onChange="uploadFile ();" />
<input type="button" name="uploadbutton" id="uploadbutton"
value="Upload" class="button" />
</td>
</tr>
</table>
</form>
</body>
</html>
我切换到帧文件上传。但是,不会显示attachmentfile id。它已启用并存在,但未显示。因此,当我执行以下操作时:driver.findElement(By.id(“attachmentfile”)).sendKeys(“C:\\Image.jpg”),它会给出元素不可见异常。不确定这是否是IE不支持的功能的情况。驱动程序不会与所有浏览器上都不显示的元素交互。试试看怎么样?((JavascriptExecutor)driver.executeScript(“document.getElementById(“attachmentfile”).value=“filename”)”@A.J您不能通过JavaScript更改
元素的值。这是一个安全问题。否则,网站只需将您电脑的所有内容上传到web上即可。