qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

Selenium2.0功能测试之文件上传(Java版)

  对于上传文件的用例,首先需要找到上传文件的对象,然后直接往这个对象sendKeys,传入需要上传文件的正确路径,绝对路径和相对路径都可以的,但是上传的文件必须存在,否则会报错。下面直接看例子吧:
package org.coderinfo.demo;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
/**
* @author Coderinfo
* @Email: coderinfo@163.com
*/
public class UpdateFile {
private static final String URL = "file:///C:/Documents and Settings/user/Desktop/Selenium/update_file.html";
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get(URL);
// Use API:sendKeys to update file
driver.findElement(By.id("update")).sendKeys("C:/Documents and Settings/user/Desktop/Selenium/update_file.html");
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.close();
}
}
  本测试的页面源码:
<!DOCTYPE html>
<html>
<head>
<title>Update File</title>
<style>
h2 {
text-align : center
}
</style>
</head>
<body>
<h2>Update File Demo</h2>
<form>
Update File:<input type="file" id="update"/>
</form>
</body>
</html>
相关文章
Selenium2.0功能测试之Web元素的操作

posted on 2013-10-31 11:21 顺其自然EVO 阅读(238) 评论(0)  编辑  收藏 所属分类: selenium and watir webdrivers 自动化测试学习


只有注册用户登录后才能发表评论。


网站导航:
 
<2013年10月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜