Selenium Webdriver FIle Upload error element ice:i

2019-09-05 03:56发布

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.

The entire element code is:

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

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

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

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>");

The error message shows as: 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.

4条回答
Lonely孤独者°
2楼-- · 2019-09-05 04:24

Please confirm that the input element is visible

Do not click on the browse button, it will open an system level dialogue box to upload the file & Its very tedious to handle this in selenium.

you can use the following method:

driver.find_element(:id,'videoupload').send_keys("E:\\video.flv")

Please check the "\\" in your code.

Please Keep in mind that the upload will work only If the element you send a file should be in the form

Hope this will work for you.

Cheers!!

查看更多
做个烂人
3楼-- · 2019-09-05 04:27

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.

You can't search for elements contained in frames, you have to switch your driver's context to that frame first.

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

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).

查看更多
forever°为你锁心
4楼-- · 2019-09-05 04:32

Try this code:

driver.FindElement(By.XPath("/html/body/div[2]/div[5]/div/div/div/div[2]/div[2]/div[1]/div/div[1]")).click();
查看更多
Fickle 薄情
5楼-- · 2019-09-05 04:34

File Upload Using SendKeys

FirefoxDriver driver = new FirefoxDriver();

driver.get("URl");

File file=null;

try
{
file=new File("file path");
}

catch(Exception e)
{
e.printStackTrace();
}

Assert.assertTrue(file.exists());

WebElement browserButton=driver.findElement(By.id("button Id"));

browserButton.sendkeys(file.getAbsolutePath());
查看更多
登录 后发表回答