[英]Selenium: For loop breaks find_element
这真的让我难过。 这与以下问题有关: Selenium:遍历元素组
这工作正常:
print driver.find_element_by_xpath('//div[@class="_1zf"]//div[@class="_946"]//div[contains(text(), "Lives in")]').text
这不是:
group = driver.find_elements_by_class_name('_1zf')
for person in group:
print person.find_element_by_xpath('.//div[@class="_946"]//div[contains(text(), "Lives in")]').text
当我将其放入循环中时,突然找不到该元素。
@AutomaticStatic:
group是元素列表,person是group元素列表中存在的元素之一
group = driver.find_elements_by_class_name('_1zf')
# group is the list of elements
for person in group:
print person.text
# person is one of the elements present in the list of elements in group
希望它现在可以为您工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.