CSS获取兄弟节点
- css匹配到多个元素获取兄弟节点
- aui-table-row.aui-table__row:nth-of-type(1)
- 使用场景一般为同样的css获取到多个元素,然后可以通过获取text等其他
from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Chrome() css_loc = (By.CSS_SELECTOR,"aui-table-row.aui-table__row") eles = driver.find_elements(*css_loc) css_path="" # 通过判断text,找到对应元素 for inx, ele in enumerate(eles): if ele.text.find("xxx"): css_path = "aui-table-row.aui-table__row:nth-of_type({})".format(inx+1) #获取到对应元素下面的button new_css_loc = (By.CSS_SELECTOR,css_path+" button")