码迷,mamicode.com
首页 > 其他好文 > 详细

Message: u'$ is not defined' ; Stacktrace

时间:2014-06-15 08:41:16      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   java   http   ext   

status.html

<html>
        <head>
            <meta http-equiv="content-type" content="text/html;charset=utf-8" />
            <title>status</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>status</h3>
            <div class="row-fluid">
                <div class="span3">     
                    <input name="user" placeholder="Disabled TextField" disabled  />                
                </div>      
                <div class="span3">
                    <a class="btn disabled">Disabled Button</a>
                </div>
                <div class="span3">
                    <input name="radio" type="radio" />
                </div>
            </div>      
        </body>
        <script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
    </html>

  

 

status.py

# -*- coding: utf-8 -*- 
from selenium import webdriver
from time import sleep
import os
if ‘HTTP_PROXY‘in os.environ: del os.environ[‘HTTP_PROXY‘]

dr = webdriver.Chrome()
file_path = ‘file:///‘ + os.path.abspath(‘status.html‘)
dr.get(file_path)

text_field = dr.find_element_by_name(‘user‘)
print text_field.is_enabled()

# 直接用enabled?方法去判断该button的话返回的会是true
# 这是因为button是使用css方法去disabled的,并不是真正的disable
# 这时候需要判断其class里是否有disabled这值来判断其是否处于disable状态
print dr.find_element_by_class_name(‘btn‘).is_enabled()

# 隐藏掉text_field
# 判断其是否显示
dr.execute_script(‘$(arguments[0]).hide()‘, text_field)
print text_field.is_displayed()

# 使用click方法选择raido
radio = dr.find_element_by_name(‘radio‘)
radio.click()
print radio.is_selected()

# 判断元素是否存在
try:
    dr.find_element_by_id(‘none‘)
except: 
    print ‘element does not exist‘

dr.quit()

  执行后会报错,经与乙醇沟通后发现是谷歌被墙导致代码木有完全加载.修改代码如下:

#coing=utf-8

from selenium import  webdriver
from time import  sleep
import  os

if ‘HTTP_PROXY‘ in os.environ: del os.environ[‘HTTP_PROXY‘]

dr = webdriver.Firefox()
file_path = ‘file:///‘ + os.path.abspath(‘status.html‘)
dr.get(file_path)

text_field = dr.find_element_by_name(‘user‘)
print( text_field.is_enabled())

print(dr.find_element_by_class_name(‘btn‘).is_enabled())

myjs = ‘document.all.user.style.display = "none";‘
dr.execute_script(myjs)

print( text_field.is_displayed())

radio = dr.find_element_by_name(‘radio‘)
radio.click()
print(radio.is_selected())

try:
    dr.find_element_by_id(‘none‘)
except:
    print(‘element does not exist‘)


dr.quit()

  

Message: u'$ is not defined' ; Stacktrace,布布扣,bubuko.com

Message: u'$ is not defined' ; Stacktrace

标签:style   class   blog   java   http   ext   

原文地址:http://www.cnblogs.com/xiaobaichuangtianxia/p/3785829.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!