您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源功能測(cè)試工具 > Selenium
輕松自動(dòng)化---selenium-webdriver(python) (八)
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/8/16 13:47:59 ] 推薦標(biāo)簽:

  隱藏元素

  js.html

<html>
    <head>
      <meta http-equiv="content-type" content="text/html;charset=utf-8" />
      <title>js</title>   
      <script type="text/javascript" async="" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
      <link href=http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css rel="stylesheet" />      
      <script type="text/javascript">
        $(document).ready(function(){
          $('#tooltip').tooltip({"placement": "right"});
        });
      </script>
    </head>

    <body>
      <h3>js</h3>
      <div class="row-fluid">
        <div class="span6 well">      
          <a id="tooltip" href="#" data-toggle="tooltip" title=" selenium-webdriver(python)">hover to see tooltip</a>
          <a class="btn">Button</a>
        </div>    
      </div>      
    </body>
    <script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
  </html>

  (保持html文件與執(zhí)行腳本在同一目錄下)

  執(zhí)行js一般有兩種場(chǎng)景:

  一種是在頁面上直接執(zhí)行JS

  另一種是在某個(gè)已經(jīng)定位的元素上執(zhí)行JS

#coding=utf-8
from selenium import webdriver
import time,os

driver = webdriver.Firefox()
file_path =  'file:///' + os.path.abspath('js.html')
driver.get(file_path)

#######通過JS 隱藏選中的元素#########
#第一種方法:
driver.execute_script('$("#tooltip").fadeOut();')
time.sleep(5)

#第二種方法:
button = driver.find_element_by_class_name('btn')
driver.execute_script('$(arguments[0]).fadeOut()',button)
time.sleep(5)

driver.quit()

上一頁123下一頁
軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd