Selenium Webdriver文件上传错误元素ice:inputFile [英] Selenium Webdriver FIle Upload error element ice:inputFile

查看:102
本文介绍了Selenium Webdriver文件上传错误元素ice:inputFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一篇文章,很抱歉再次提出相同的问题.我在Selenium Web驱动程序中上传文件时遇到问题.我在这个论坛上搜索了很多东西,但是解决方案对我不起作用.作为文件浏览按钮的元素嵌入在文件文本区域(即在通过文件浏览对话框浏览后打印文件路径的位置),但是上载按钮是单独的.

this is my first post and sorry for asking the same question once again. I am stuck with a issue regarding uploading a file in Selenium Web Driver. I have searched a lot in this forum but the solutions are not working for me. The element which is the file Browse button is embedded in the file text area ( i.e. where the path of the file gets printed after the browsing through file browse dialog box), but the upload button is separate.

整个元素代码为:

<input class="iceInpFileTxt" type="file" size="35" name="upload">

我无法使用click()方法单击浏览"按钮.我也尝试过使用Autoit/Robot.

I am unable to click on the "browse" button using click() method. I have tried using Autoit/Robot also.

JSP页面中元素的代码: <ice:inputFile id="fileUpload" width="600" autoUpload="true" value="#{practitionerLoadDataBean.inputFile}" actionListener="#{practitionerLoadControllerBean.browse}"/>

The code of the element from JSP page: <ice:inputFile id="fileUpload" width="600" autoUpload="true" value="#{practitionerLoadDataBean.inputFile}" actionListener="#{practitionerLoadControllerBean.browse}"/>

我知道输入类型是文件,所以sendkeys()应该可以工作.我一直在尝试的代码是:

I know the input type is file so sendkeys() should work. The codes I have been trying are:

WebElement elem = driver.findElement(By.xpath("//input[@name='upload']")); elem.sendKeys("<PATH>");

WebElement elem = driver.findElement(By.xpath("//input[@name='upload']")); elem.sendKeys("<PATH>");

错误消息显示为: org.openqa.selenium.remote.ErrorHandler$UnknownServerException:Unable to locate element: {"method":"xpath","selector":"//input[@name='upload']"}

请让我知道我的失误在哪里.预先感谢.

Please let me know where I my mistake is. Thanks in advance.

推荐答案

如果该元素只是不可见,则可以找到该元素,但您将无法与其交互.通常的解决方案是环顾四周.

If the element was simply invisible, it would have been found, but you wouldn't be able to interact with it. The usual solution is to look around for frames.

您无法搜索框架中包含的元素,必须将驱动程序的上下文切换到该框架首先.

driver.switchTo().frame("frameName");

然后,您将能够找到元素并按常规方式上传文件(请使用此处其他答案所描述的sendKeys()方法).

Then you'll be able to find the element and upload the file the usual way (please, use the sendKeys() method describes by other answers in here).

这篇关于Selenium Webdriver文件上传错误元素ice:inputFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆