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 閱讀(247) 評論(0)  編輯  收藏 所屬分類: selenium and watir webdrivers 自動化測試學習

          <2013年10月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 苍梧县| 永登县| 子长县| 武清区| 偏关县| 比如县| 云浮市| 南澳县| 兴山县| 成都市| 青铜峡市| 威信县| 衡山县| 陆河县| 邯郸县| 本溪市| 碌曲县| 砚山县| 贵阳市| 莱西市| 延寿县| 达日县| 丽江市| 咸宁市| 怀安县| 太仓市| 东乌| 许昌县| 石景山区| 南木林县| 岳西县| 凤庆县| 讷河市| 高州市| 苍梧县| 龙里县| 佛坪县| 五峰| 乐东| 武清区| 台北县|