温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

selenium学习:定位一组元素

发布时间:2020-06-15 07:54:55 来源:网络 阅读:637 作者:91ctt 栏目:软件技术

文件名:checkbox.html

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>Checkbox</title>
<link href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.js">
</script>
</head>
<body>
		<h4>Checkbox</h4>
		<div class="well">  		
			<form class="form-horizontal">  
				<div class="control-group">
					<label class="control-label" for='c1'>checkbox1</label>
					<div class="controls">
						<input type="checkbox" id="c1"/>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for='c2'>checkbox2</label>
					<div class="controls">
						<input type="checkbox" id="c2"/>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for='c3'>checkbox3</label>
					<div class="controls">
						<input type="checkbox" id="c3"/>
					</div>
				</div>
			</form>  
		</div>  
	</body>	
</html>

文件名:test10.py

from selenium import webdriver
import os,time
driver = webdriver.Chrome()
file_path='file:///'+os.path.abspath('checkbox.html')
driver.get(file_path)

inputs = driver.find_elements_by_tag_name('input')
for i in inputs:
    if i.get_attribute('type')=='checkbox':
        i.click()
        time.sleep(1)
driver.quit()

test10.py代码中的意思:访问checkbox.html

通过tag方法访问checkbox.html中所有的input元素

找到input元素之后,通过判断input属性中的"chekcbox"属性,从而定位出需要定位的一组元素

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI