我正在尝试获取列表的值。我有可能得不到任何值(value),但想继续其余的代码,但它失败了。如何处理列表中没有值的情况。
WebDriverWait(self.driver, 10, 0.1).until(
EC.presence_of_element_located((By.CSS_SELECTOR, self.e_css_project_search)))
projects = self.driver.find_elements_by_css_selector(self.e_css_project_search)
pro_flag = False
print(projects)
当我没有得到任何值时,它会发生异常。
最佳答案
检查列表的长度
计数。如果长度>0,它将打印列表。否则继续。
while(True):
projects=WebDriverWait(self.driver, 10, 0.1).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, self.e_css_project_search)))
if(len(projects)>0):
print(projects)
break
else:
continue
关于python - find_elements_by_css_selector 没有给我任何输出,如何处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56023341/