组元素定位
<!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()