使用Selenium实现图片上传

来源:互联网 发布:科一考试软件 编辑:程序博客网 时间:2024/05/20 12:49

环境:

windows xp, 

firefox 11.0, 

selenium 2.0


假设我们有一个如下所示的上传按钮

<input id="upload", type=“file”>

可以使用如下代码实现上传

Element btn = driver.findElement(By.id('upload'));btn.click();btn.sendKeys([your_img_path])// click 上传或者确认按钮


注意,这样做,不会出现native dialog, 但是最终效果和手动操作是一致的


参考:http://blog.sina.com.cn/s/blog_7407815a010170yf.html

原创粉丝点击