ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

UI自动化测试-09-Selenium元素定位--组元素定位

2022-01-22 19:00:07  阅读:38  来源: 互联网

标签:定位 -- text 元素 driver ele eles print find


组元素定位

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!--下面两个节点用于兄弟节点定位-->
<div>brother 1</div>
<div id="D"></div>
<div>brother 2</div>
</body>
</html>

from selenium import webdriver
from time import sleep

'''
元素组定位方法
'''

driver = webdriver.Chrome()
driver.get('E:\XueXi\ZDH\DaiMa\DaiMa\CZBK\one\myhtml4.html')

ele = driver.find_element_by_tag_name('div')
eles = driver.find_elements_by_tag_name('div')

print(type(ele))
print(ele.text)
print(type(eles))
print(eles[2].text)


sleep(1)
driver.quit()


from selenium import webdriver
from time import sleep

'''
要求打印当前页面所有缺陷的状态
'''

username = 'amdin'
driver = webdriver.Chrome()
driver.implicitly_wait(20)
driver.maximize_window()
driver.get("http://192.168.229.129/redmine/login")
driver.find_element_by_id('username').send_keys('admin')
driver.find_element_by_id('password').send_keys('test1234')
driver.find_element_by_id('login-submit').click()
sleep(2)
driver.get('http://192.168.229.129/redmine/projects/project3/issues')

'''
通过classname定位到元素组,然后循环读取列表中的元素,打印其文字
'''

eles = driver.find_elements_by_class_name('status')
for ele in eles:
if ele.text=='状态':
continue
else:
print(ele.text)


driver.quit()

标签:定位,--,text,元素,driver,ele,eles,print,find
来源: https://www.cnblogs.com/jenny-jenny/p/15834780.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有