通过一个元素, 找到他的父级元素parent::xxx, 然后找 父级元素后面的元素following-sibling::xxx 的子元素/
可以通过这种找列表, 多个子元素情况
@pytest.mark.run(order=400007)
@allure.title("@群成员")
def test_艾特群成员(self):
try:
# # 换个 群,单聊拉群1, 非群主
# self.driver.find_element(by=By.NAME, value="搜索").click()
# time.sleep(1)
# self.driver.find_element(by=By.NAME, value="搜索").send_keys("单聊拉群1")
# time.sleep(1)
# self.driver.find_element(by=By.NAME, value="单聊拉群1").click()
# time.sleep(1)
# # 光标输入框
# self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/Group/Text').click()
# 输入艾特
self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/Group/Text').send_keys("@")
all_name = self.driver.find_elements(By.XPATH,
'//Document[@Name="hwork-desktop-im"]/List/ListItem/Text[@Name="所有成员"]/parent::ListItem/following-sibling::ListItem/Text')
# 第一个人
first_name = all_name[0].text
# 输入群里, 所有成员 中,排名第一个人的姓
self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/Group/Text').send_keys(first_name[0])
time.sleep(1)
# 断言第一个人名字,可见
assert self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/List/ListItem/Text[@Name="'+first_name+'"]').is_displayed()
pyautogui.press('backspace')
# q群内总人数
all_amount = self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/Text[2]').text
if self.driver.find_element(By.XPATH,
'//Document[@Name="hwork-desktop-im"]/List/ListItem/Text[@Name="群成员"]/parent::ListItem/following-sibling::ListItem/Text[last()]').text == "群主":
assert len(all_name)+2 == int(all_amount)
else:
assert len(all_name) + 1 == int(all_amount)
finally:
# 清空输入框再关闭
self.driver.find_element(By.XPATH, '//Document[@Name="hwork-desktop-im"]/Group/Text').clear()
self.driver.close()