qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請(qǐng)?jiān)L問 http://qaseven.github.io/

          Selenium 利用javascript 控制滾動(dòng)條

            以下備注所用test.html 的代碼(我也是在網(wǎng)上找的,簡(jiǎn)單的修改顯示文字而已),供大家使用:

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
          <html xmlns=http://www.w3.org/1999/xhtml>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>Selenium Study</title>
          <script language="JavaScript">
          function check(){
          var clientHeight = document.getElementById('text').clientHeight;
          var scrollTop    = document.getElementById('text').scrollTop;
          var scrollHeight = document.getElementById('text').scrollHeight;
          if(clientHeight + scrollTop < scrollHeight){
          alert("Please view top news terms !"); return false;
          }else{
          alert("Thanks !");
          }
          }
          function set()
          {
          document.getElementById('text').scrollTop=10000;
          }
          </script>
          </head>
          <body>
          <form id="form1" method="post" onsubmit="return check();">
          <textarea id="text" name="text" cols="70"  rows="14">
          Selenium IDE is the a Firefox plugin that does record-and-playback of interactions with the browser. Use this to either create simple scripts, assist in exploratory testing. It can also export Remote Control or WebDriver scripts, though they tend to be somewhat brittle and should be overhauled into some sort of Page Object-y structure for any kind of resiliency.
          Selenium IDE is the a Firefox plugin that does record-and-playback of interactions with the browser. Use this to either create simple scripts, assist in exploratory testing. It can also export Remote Control or WebDriver scripts, though they tend to be somewhat brittle and should be overhauled into some sort of Page Object-y structure for any kind of resiliency.
          Selenium IDE is the a Firefox plugin that does record-and-playback of interactions with the browser. Use this to either create simple scripts, assist in exploratory testing. It can also export Remote Control or WebDriver scripts, though they tend to be somewhat brittle and should be overhauled into some sort of Page Object-y structure for any kind of resiliency.
          Selenium IDE is the a Firefox plugin that does record-and-playback of interactions with the browser. Use this to either create simple scripts, assist in exploratory testing. It can also export Remote Control or WebDriver scripts, though they tend to be somewhat brittle and should be overhauled into some sort of Page Object-y structure for any kind of resiliency.
          </textarea><br /><br />
          <input type="submit" id="submit" name="submit" value="Submit" />
          </form>
          </body>
          </html>

           < xmlnamespace prefix ="o" ns ="urn:schemas-microsoft-com:office:office" />

            在工作中,遇到這樣的問題,注冊(cè)時(shí)的法律條文需要閱讀,判斷用戶是否閱讀的標(biāo)準(zhǔn)是:滾動(dòng)條是否拉到最下方。以下是我模擬的2種情況:

            1.滾動(dòng)條在上方時(shí),點(diǎn)擊submit用戶,提示:please view top new terms!

            2.滾動(dòng)條在最下方,點(diǎn)擊submit用戶,提示:Thanks!

            以上如果是手動(dòng)測(cè)試顯然很簡(jiǎn)單,那么如何用selenium測(cè)試呢。

            經(jīng)過IDE錄制,發(fā)現(xiàn)拖動(dòng)滾動(dòng)條的動(dòng)作并沒有錄制下來!那么能想到的方法只有利用javascript來設(shè)置了。

            Baidu后得到的知識(shí)是:

            <body   onload= "document.body.scrollTop=0 ">


            也就是說如果scrollTop=0 時(shí),滾動(dòng)條就會(huì)默認(rèn)在最上方

            <body   onload= "document.body.scrollTop=100000 ">

            也就是說如果scrollTop=100000 時(shí),滾動(dòng)條就會(huì)默認(rèn)在最下方

            通過以上,以及學(xué)習(xí)的selenium調(diào)用javascript的知識(shí):

            在javascript中調(diào)用頁(yè)面上的元素的方法

            this.browserbot.getUserWindow().document.getElementById('text')

            這樣設(shè)置元素的屬性就很簡(jiǎn)單了

            this.browserbot.getUserWindow().document.getElementById('text').scrollTop=10000"

            經(jīng)過修改的IDE腳本

            以下備注所用test.html 的代碼(我也是在網(wǎng)上找的,簡(jiǎn)單的修改顯示文字而已),供大家使用:

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
          <html xmlns=http://www.w3.org/1999/xhtml>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>Selenium Study</title>
          <script language="JavaScript">
          function check(){
          var clientHeight = document.getElementById('text').clientHeight;
          var scrollTop    = document.getElementById('text').scrollTop;
          var scrollHeight = document.getElementById('text').scrollHeight;
          if(clientHeight + scrollTop < scrollHeight){
          alert("Please view top news terms !"); return false;
          }else{
          alert("Thanks !");
          }
          }
          function set()
          {
          document.getElementById('text').scrollTop=10000;
          }
          </script>
          </head>
          <body>
          <form id="form1" method="post" onsubmit="return check();">
          <textarea id="text" name="text" cols="70"  rows="14">
          Selenium IDE is the a Firefox plugin that does record-and-playback of interactions with the browser. Use this to either create simple scripts, assist in exploratory testing. It can also export Remote Control or WebDriver scripts, though they tend to be somewhat brittle and should be overhauled into some sort of Page Object-y structure for any kind of resiliency.
          Selenium IDE is the a Firefox plugin that does record-and-playback of interactions with the browser. Use this to either create simple scripts, assist in exploratory testing. It can also export Remote Control or WebDriver scripts, though they tend to be somewhat brittle and should be overhauled into some sort of Page Object-y structure for any kind of resiliency.
          Selenium IDE is the a Firefox plugin that does record-and-playback of interactions with the browser. Use this to either create simple scripts, assist in exploratory testing. It can also export Remote Control or WebDriver scripts, though they tend to be somewhat brittle and should be overhauled into some sort of Page Object-y structure for any kind of resiliency.
          Selenium IDE is the a Firefox plugin that does record-and-playback of interactions with the browser. Use this to either create simple scripts, assist in exploratory testing. It can also export Remote Control or WebDriver scripts, though they tend to be somewhat brittle and should be overhauled into some sort of Page Object-y structure for any kind of resiliency.
          </textarea><br /><br />
          <input type="submit" id="submit" name="submit" value="Submit" />
          </form>
          </body>
          </html>

          posted on 2013-09-11 11:35 順其自然EVO 閱讀(393) 評(píng)論(0)  編輯  收藏 所屬分類: selenium and watir webdrivers 自動(dòng)化測(cè)試學(xué)習(xí)

          <2013年9月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 博野县| 云南省| 通海县| 来宾市| 搜索| 南木林县| 长垣县| 景宁| 修水县| 靖远县| 海门市| 平罗县| 东乌珠穆沁旗| 容城县| 延寿县| 金坛市| 濉溪县| 瑞安市| 建昌县| 磐安县| 大连市| 文安县| 甘德县| 三原县| 云阳县| 绩溪县| 玉树县| 宁波市| 黄龙县| 杭锦旗| 策勒县| 大冶市| 鄂温| 德化县| 红安县| 富宁县| 岳普湖县| 泰兴市| 响水县| 津市市| 邛崃市|