【问题标题】:Struggling with File Upload in a VisualForce Page using Selenium WebDriver (ChromeDriver 2.12)使用 Selenium WebDriver (ChromeDriver 2.12) 在 VisualForce 页面中处理文件上传问题
【发布时间】:2015-02-21 05:19:21
【问题描述】:

我在使用 VisualForce 文件上传对话框时需要一些帮助。它在 Selenium IDE 上运行得非常好,但是当我尝试让它与 WebDriver 一起工作时,驱动程序甚至无法找到元素,更不用说使用它们了。

这是我要测试的文件上传器的 HTML 代码:

<div class="form-group">
<label class="col-xs-12">
File
<span class="required">*</span>
</label>
<div class="col-xs-12">
<input id="files" type="file" name="files">
</div>
</div>

这是我的 Selenium IDE 代码,它在文件上传器中输入文件的路径(效果很好):

<td>type</td>
<td>id=files</td>
<td>C:\Users\filefolder\file.rtf</td>

这是我的 Selenium WebDriver 代码(不起作用):

try{
    driver.findElement(By.id("files")).sendKeys("C:\\Users\\filefolder\\file.rtf");
}
catch(Exception e){
    verificationErrors.append("Could not work with file input; "+e.toString());
}

当我运行它时,输出如下: java.lang.AssertionError:无法处理文件输入; org.openqa.selenium.NoSuchElementException: 没有这样的元素

如果您需要更多详细信息来回答这个问题,请告诉我。 非常感谢您在这里的帮助!

【问题讨论】:

  • 你能提供页面的实际html吗?
  • 这可能是一个错字,但]files] 是从哪里得到的?
  • 你说得对,赛弗。那个结尾括号是一个错字。我纠正了它,但不幸的是,它仍然不起作用。我在上面添加了与文件对话框相关的 HTML 代码。需要帮助请叫我。谢谢!

标签: java file selenium upload visualforce


【解决方案1】:

尝试显式等待,如果页面包含多个 type='file' 元素,请告诉我

By locator = By.cssSelector("[type='file'][id='files']")
WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
driver.findElement(locator).sendKeys("C:\\Users\\filefolder\\file.rtf");

【讨论】:

  • 如果有异常请告诉我
猜你喜欢
  • 2020-10-24
  • 2020-09-13
  • 2012-06-30
  • 2021-05-24
  • 1970-01-01
  • 1970-01-01
  • 2017-11-24
  • 1970-01-01
相关资源
最近更新 更多