[英]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.