首页 文章

Selenium Webdriver FIle上传错误元素ice:inputFile

提问于
浏览
0

这是我的第一篇文章,很抱歉再次提出同样的问题 . 我遇到了有关在Selenium Web Driver中上传文件的问题 . 我在这个论坛上搜索了很多,但解决方案对我不起作用 . 作为文件“浏览”按钮的元素嵌入在文件文本区域中(即,在浏览文件浏览对话框之后打印文件的路径),但是上载按钮是分开的 .

整个元素代码是:

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

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

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

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

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']"}

请让我知道我的错误在哪里 . 提前致谢 .

4 回答

  • 1

    如果元素只是不可见,那么它就会被找到,但你无法与之交互 . 通常的解决方案是环顾四周 .

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

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

  • 0

    请确认输入元素是可见的

    不要点击浏览按钮,它会打开一个系统级别的对话框来上传文件,它在selenium中处理这个非常繁琐 .

    您可以使用以下方法:

    driver.find_element(:身份证, 'videoupload')send_keys( “E:\ video.flv”) .

    请检查代码中的“\” .

    请记住,上传仅适用于您发送文件的元素应该在表单中

    希望这对你有用 .

    干杯!!

  • 0

    使用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());
    
  • 0

    试试这段代码:

    driver.FindElement(By.XPath("/html/body/div[2]/div[5]/div/div/div/div[2]/div[2]/div[1]/div/div[1]")).click();
    

相关问题