selenium元素定位

上一篇 / 下一篇  2016-07-06 17:59:02 / 个人分类:selenium

页面源码:
<body nLoad="window_onload()">
<div class="main">
   <div class="main_top_1"></div>
   <div class="main_top_2"></div>
   <div class="main_top_3">
    <div class="di_login">
    <form. ACTION='/hfStlWeb/stl/sysLogin.action?pts=1467798962181' method="post" name="form1" id="form1">
     <table width="300px" border="0" cellpadding="0" cellspacing="0" bordercolor="#003366">
       <tr>
         <td width="20%" height="40" align="right">用户名:</td>
         <td colspan="2"  width="50%" class="tdbg"><input class="input" type="text" name="j_username" id="j_username" size="20" value="dev" /></td>
       </tr>
       <tr>
         <td height="40" align="right">密 码:</td>
         <td colspan="2" class="tdbg"><input class="input" type="password" name="j_password" id="j_password" size="20" maxlength="10" value="dev123" /></td>
       </tr>
       <tr>
         <td height="40" align="right">验证码:</td>
         <td class="tdbg"><input nfocus="showVCode()" class="input" type="text" name="j_verifyCode" id="j_verifyCode" size="15" maxlength="4" nkeypress="subForm();"/>
          </td>
         <td id="vCodeTD" style="display: none;"  ><div class="verf"><img id="verifyCodeImg"  title="" alt="验证码" width="60" style="cursor:hand" nclick="changeVCode(this);"/></div></td>
       </tr>
       <tr>
         <td colspan="3" align="center"> <a nclick="form1_onsubmit()" href="#"><img src="/hfStlWeb/static/images/but.png?pts=1467798962181" width="70" height="25" border="0" /></a>
         <input type="hidden" name="clientHeight" id="clientHeight" value=""/>
         </td>
       </tr>
       <tr>
           <td colspan="3"><div class="STYLE1" align="center">&nbsp;&nbsp;</div></td>
          </tr>
     </table>
     </form>
     </div>
   </div>
   <div class="main_di"></div>
 </div>
</body>

python定位到页面元素位置,byId 和 xpath两种定位方式

# coding = utf-8
import os
import selenium

print selenium.__file__

from selenium import webdriver
IEDriverServer = "C:\Program Files\Internet Explorer\IEDriverServer.exe"
os.environ["webdriver.ie.driver"] = IEDriverServer
driver =  webdriver.Ie(IEDriverServer)

driver.get("http://*.*.*.*:####/hfWeb/")
driver.find_element_by_id("j_username").send_keys()
driver.find_element_by_id("j_password").send_keys()
driver.find_element_by_id("j_verifyCode").send_keys('1234')

driver.find_element_by_xpath("//a[@href='#']").click()

time.sleep(3)

driver.quit()


自己留存,公司记事本不能网络同步了 悲催

TAG: 元素

fhhh_eyou的个人空间 引用 删除 fhhh_eyou   /   2016-07-07 10:31:05
 

评分:0

我来说两句

日历

« 2024-04-25  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 5419
  • 日志数: 4
  • 建立时间: 2016-06-03
  • 更新时间: 2016-07-07

RSS订阅

Open Toolbar