<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    qileilove

    blog已經(jīng)轉(zhuǎn)移至github,大家請訪問 http://qaseven.github.io/

    Selenium WebDriver處理Table

     首先,html table是由 table 元素以及一個或多個 tr、th 或 td 元素組成。
      for example:
      這是一個簡單的html table:
      源碼如下:
    <html>
    <head>
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>for selenium test </title>
    </script>
    </head>
    <body>
    <div align="center">
    <h4 align="left">               table head:</h4>
    <table border="2" width="90%" id="table138" bordercolorlight="#CCCCCC" cellspacing="0" cellpadding="0" bordercolordark="#CCCCCC" style="border-collapse: collapse">
    <tr align="center">
    <td height="26" width="10%" align="center" bgcolor="#CCEEAA" ><Strong>Test Case ID</Strong></td>
    <td  height="26" width="35%" align="center" bgcolor="#EEEEAA" ><Strong>Steps</Strong></td>
    <td  height="26" width="30%" align="center" bgcolor="#00EEEE" ><Strong>Expect</Strong></td>
    <td  height="26" align="center" bgcolor="#EE00EE" ><Strong>Actual</Strong></td>
    <td  height="26" align="center" bgcolor="#00EE00" ><Strong>PASS/FAIL</Strong></td>
    </tr>
    <tr align="center">
    <td height="26" align="center" bgcolor="#CCEEAA">ENT#-12345</td>
    <td  height="26" align="left" bgcolor="#EEEEAA" >1.open baidu.com ,wait for the page load</br>2.enter "selenium" in the input box" </br>3.click search button  </td>
    <td  height="26" align="left" bgcolor="#00EEEE" >"Selenium - Web Browser Automation" link be the first of the search result</td>
    <td  height="26" align="left" bgcolor="#EE00EE" >Selenium - Web Browser Automation is appear the page,but is not the first link</td>
    <td  height="26" align="center" bgcolor="#00EE00" >FAIL</td>
    </tr>
    </tr>
    <tr align="center">
    <td height="26" align="center" bgcolor="#CCEEAA">ENT#-12346</td>
    <td  height="26" align="left" bgcolor="#EEEEAA" >1.click the "Selenium - Web Browser Automation" link</br>2.wait for page load</td>
    <td  height="26" align="left" bgcolor="#00EEEE" >open the official home page of selenium</td>
    <td  height="26" align="left" bgcolor="#EE00EE" >selenium home page is load </td>
    <td  height="26" align="center" bgcolor="#00EE00" >FAIl</td>
    </tr>
    </tr>
    <tr align="center">
    <td height="26" align="center" bgcolor="#CCEEAA">ENT#-12347</td>
    <td  height="26" align="left" bgcolor="#EEEEAA" >1.click baidu snapshot of selenium web page </br>2. wait for the page load</td>
    <td  height="26" align="left" bgcolor="#00EEEE" >the snapshot web page can be show up</td>
    <td  height="26" align="left" bgcolor="#EE00EE" >the snapshot web page is show up</td>
    <td  height="26" align="center" bgcolor="#00EE00" >PASS</td>
    </tr>
    </table>
    </div>
    </body>
    </html>
    那么問題就來了,我想通過xpath獲取這個table的每一個cell的值(比如獲取expect的值),該怎么做。
      如果這個表格被改變了,增加或刪除一些行列該如何處理?
      我的solution是獲取table的base xpath,這個所謂的base xpath是指這個table的第n行第m列相同的部分,然后通過傳入n,m獲取返回值
    public static String tableCell(WebDriver driver,int row, int column)
    {
    String text = null;
    //avoid get the head line of the table
    row=row+1;
    String xpath="http://*[@id='table138']/tbody/tr["+row+"]/td["+column+"]";
    WebElement table=driver.findElement(By.xpath(xpath)); //*[@id="table138"]/tbody/tr[1]/td[1]/strong
    text=table.getText();
    return text;
    }
      所以,tableCell(driver,1,2)就能返回

    posted on 2014-12-05 12:11 順其自然EVO 閱讀(348) 評論(0)  編輯  收藏 所屬分類: 測試學習專欄

    <2014年12月>
    30123456
    78910111213
    14151617181920
    21222324252627
    28293031123
    45678910

    導航

    統(tǒng)計

    常用鏈接

    留言簿(55)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 大地资源免费更新在线播放| 免费国产午夜高清在线视频 | 免费在线观看自拍性爱视频| 四虎永久在线观看免费网站网址| 亚洲国语精品自产拍在线观看 | A片在线免费观看| 亚洲免费观看视频| 色播在线永久免费视频网站| 亚洲女初尝黑人巨高清| 国产自国产自愉自愉免费24区| 亚洲中文字幕久久精品无码喷水| 男女一边桶一边摸一边脱视频免费| 亚洲高清国产拍精品青青草原| 曰韩无码AV片免费播放不卡| 亚洲第一区精品日韩在线播放| 国产A∨免费精品视频| 国产精品V亚洲精品V日韩精品| 中国人免费观看高清在线观看二区| 国产gv天堂亚洲国产gv刚刚碰| 中文字幕在线视频免费观看| 国产精品亚洲片在线观看不卡| 99在线观看视频免费| 亚洲第一永久在线观看| 国产一精品一AV一免费孕妇 | 一级毛片在线免费播放| 亚洲精品乱码久久久久久中文字幕 | 羞羞视频在线免费观看| 亚洲天堂免费在线视频| 黄网站免费在线观看| 亚洲伊人久久大香线蕉在观| 日本免费一区尤物| sihu国产精品永久免费| 91亚洲导航深夜福利| 国产精品高清全国免费观看| 两性色午夜视频免费网| 亚洲精品无码久久久久久久| 小小影视日本动漫观看免费| 国产在线国偷精品免费看| 亚洲无砖砖区免费| 免费大黄网站在线观| 久久99青青精品免费观看|