[英]Selenium: For loop breaks find_element
This one really has me stumped. 这真的让我难过。 It's related to this question: Selenium: Iterating through groups of elements
这与以下问题有关: Selenium:遍历元素组
This works fine: 这工作正常:
print driver.find_element_by_xpath('//div[@class="_1zf"]//div[@class="_946"]//div[contains(text(), "Lives in")]').text
This does not: 这不是:
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
When I put it in the loop, suddenly the element can't be found. 当我将其放入循环中时,突然找不到该元素。
@AutomaticStatic: @AutomaticStatic:
group is the list of elements person is one of the elements present in the list of elements in group 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
Hope so it will work now for you. 希望它现在可以为您工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.