Python Selenium - 循环遍历子元素

时间:2021-02-27 02:37:45

标签: python selenium loops element

enter image description here

如何遍历“ctbdy”的元素并检查“bl_name bln_end”是否为“Materials”?

1 个答案:

答案 0 :(得分:0)

如果所有 span 元素都具有相同的类名。获取元素跨度列表。然后使用循环逐个检查跨度文本。

list_span_elements = driver.find_elements_by_xpath("//div[@class='ctbdy']/p/span[@class='bl_name bln_end']")
for element in list_span_elements:
    if (element.text == "Materials"):
        print("Find element with Materials")