qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          Selenium WebDriver如何查找WebElement

          這里從我們team的代碼中來總結下常見的幾種找頁面元素的方法:
            (1)通過WebElement的ID
            如果某個WebElement提供了ID,
            <input type="text" name="passwd"id="passwd-id" />
            (2)通過WebElement的name查找:
            WebElement element = driver.findElement(By.name("passwd"));
            (3)通過WebElement的xpath查找:
            WebElement element =driver.findElement(By.xpath("http://input[@id='passwd-id']"));
            (4)通過WebElement的樣式查找:
            <div class="cheese"><span>Cheddar</span></div><divclass="cheese"><span>Gouda</span></div>
            可以通過這樣查找頁面元素:
            List<WebElement>cheeses = driver.findElements(By.className("cheese"));
            (5)通過超鏈接文本查找:
            <a>cheese</a>>
            那么可以通過這樣查找:
            WebElement cheese =driver.findElement(By.linkText("cheese"));

          posted on 2014-04-17 10:34 順其自然EVO 閱讀(1136) 評論(0)  編輯  收藏 所屬分類: selenium and watir webdrivers 自動化測試學習

          <2014年4月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 长顺县| 阿拉善左旗| 天祝| 泗洪县| 纳雍县| 镇沅| 贵港市| 永宁县| 乐东| 扎赉特旗| 荆州市| 于都县| 咸宁市| 义马市| 尤溪县| 张家口市| 阜康市| 澄迈县| 福安市| 墨江| 唐河县| 绥滨县| 九龙县| 洞头县| 定边县| 宁德市| 隆昌县| 泾源县| 安吉县| 沅江市| 青铜峡市| 辽宁省| 孟津县| 广西| 南平市| 滨州市| 澄迈县| 竹山县| 安仁县| 蒙阴县| 松滋市|