用于gwt多上传组件的Selenium Webdriver

时间:2014-03-06 10:05:06

标签: java gwt file-upload selenium xpath

案例1:我正在尝试自动化多个文件上传功能。无论我给出的是什么xpath都正确地找到了元素,但是当我执行程序(使用WebDriverWait类)时它失败了,给出了以下错误

Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 5 seconds waiting for visibility of element located by By.className: gwt-FileUpload Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'

案例2:我正在尝试从本地服务器自动上传文件。无论我给出的是什么xpath都正确地找到了元素,但是当我执行程序(不使用WebDriverWait类)时,它失败了,给出了以下错误:

Exception in thread "main" org.openqa.selenium.InvalidSelectorException: The given selector //input[@class='gwt-FileUpload is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: Unable to locate an element with the xpath expression //input[@class='gwt-FileUpload

代码如下:

WebDriver driver=new FirefoxDriver();
driver.get("http://localhost:8080/application/");
driver.findElement(By.xpath("//input[@ type='text']" )).sendKeys("test");//user name
driver.findElement(By.xpath("//input[@ type='password']")).sendKeys("test");//pwd
driver.findElement(By.xpath("//button[@class='button']")).click();//WebDriverWait wait = new WebDriverWait(driver,5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//td[@id='gwt-uid-8']")));

driver.findElement(By.xpath("//td[@id='gwt-uid-8']")).click();//dropdown selection
driver.findElement(By.xpath("//td[@id='gwt-uid-3']")).click();//dropdown selection

/*wait = new WebDriverWait(driver,5);
               wait.until(ExpectedConditions.visibilityOfElementLocated(ByClassName.className("gwt-FileUpload")));*/

driver.findElement(By.xpath("//button[@class='button DecoratedFileUpload-button']")).click();//button
driver.findElement(By.xpath("//input[@class='gwt-FileUpload")).sendKeys("D:/xyz.doc");

请有人可以帮助我吗?

提前致谢

修改

即使在this link,我也无法使用gwt-upload上传文件。

0 个答案:

没有答案