标签:os.path isp ble text 对象 jquer html button 创建
在web自动化测试中,我们需要获取测试对象的四种状态
<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.html和test.py放在同一个文件夹下
创建test.py输入一下代码
from selenium import webdriver from time import sleep import os dr = webdriver.Chrome() file_path = ‘file:///‘ + os.path.abspath(‘status.html‘) dr.get(file_path) sleep(1) #直接用enabled方法去判断该button的话,返回的是true #这是因为button是使用css方法去disabled的,并不是真正的disable text_field = dr.find_element_by_name(‘user‘) print(text_field.is_enabled()) #这时候需要判断其class里是否有disabled这个值来判断其是否处于disable状态 print(dr.find_element_by_class_name(‘btn‘).is_enabled()) #判断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 exits‘) sleep(1) dr.quit()
标签:os.path isp ble text 对象 jquer html button 创建
原文地址:https://www.cnblogs.com/luoshuifusheng/p/9176760.html